How to use the routing-controllers.InternalServerError function in routing-controllers

To help you get started, we’ve selected a few routing-controllers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jmaicaaan / express-starter-ts / src / app / middlewares / errorHandler.middleware.ts View on Github external
public error(error: Error, request: Request, response: Response, next: NextFunction) {
    // in case the controllers throw invalid http error
    if (!(error instanceof HttpError)) {
      const internalError = new InternalServerError('Internal Server Error');
      return response.status(500).send(internalError);
    }
    return response.send(error);
  }
}
github geli-lms / geli / api / src / controllers / AuthController.ts View on Github external
}
    }
    if (user.role !== 'teacher' && user.role !== 'student') {
      throw new BadRequestError('You can only sign up as student or teacher');
    }
    if (user.role === 'teacher' && (typeof user.email !== 'string' || !user.email.match(config.teacherMailRegex))) {
      throw new BadRequestError(errorCodes.errorCodes.mail.noTeacher.code);
    }
    const newUser = new User(user);
    const savedUser = await newUser.save();
    // User can now match a whitelist.
    await this.addWhitelistedUserToCourses(savedUser);
    try {
      emailService.sendActivation(savedUser);
    } catch (err) {
      throw new InternalServerError(errorCodes.errorCodes.mail.notSend.code);
    }
  }
github geli-lms / geli / api / src / utilities / UnitClassMapper.ts View on Github external
private static getClassMappingForUnit(unit: IUnit): any {
    const hasNoProgressClass = Object.keys(this.classMappings).indexOf(unit.type) === -1 ;
    if (hasNoProgressClass) {
      throw new InternalServerError(`No classmapping for type ${unit.type} available`);
    }

    return this.classMappings[unit.type];
  }
github geli-lms / geli / api / src / controllers / DuplicationController.ts View on Github external
async duplicateUnit(@Param('id') id: string, @Body() data: any, @Req() request: Request) {
    const courseId = data.courseId;
    const lectureId = data.lectureId;
    try {
      const unitModel: IUnitModel = await Unit.findById(id);
      const exportedUnit: IUnit = await unitModel.exportJSON();
      return Unit.schema.statics.importJSON(exportedUnit, courseId, lectureId);
    } catch (err) {
      const newError = new InternalServerError('Failed to duplicate unit');
      newError.stack += '\nCaused by: ' + err.message + '\n' + err.stack;
      throw newError;
    }
  }
github geli-lms / geli / api / src / models / Lecture.ts View on Github external
try {
    const savedLecture = await new Lecture(lecture).save();

    const course = await Course.findById(courseId);
    course.lectures.push(savedLecture);
    await course.save();

    for (const unit of units) {
      const unitTypeClass = UnitClassMapper.getMongooseClassForUnit(unit);
      await unitTypeClass.schema.statics.importJSON(unit, courseId, savedLecture._id);
    }
    const newLecture: ILectureModel = await Lecture.findById(savedLecture._id);

    return newLecture.toObject();
  } catch (err) {
    const newError = new InternalServerError('Failed to import lecture');
    newError.stack += '\nCaused by: ' + err.message + '\n' + err.stack;
    throw newError;
  }
};
github rafaell-lycan / sabesp-mananciais-api / src / api / v2.ts View on Github external
public getByDate(@Param('date') date: string) {
    try {
      validateDate(date);

      return this.getData(date);
    } catch (error) {
      logger.error(error);
      return new InternalServerError(error.message);
    }
  }
}
github geli-lms / geli / api / src / controllers / AuthController.ts View on Github external
.catch((err) => {
        throw new InternalServerError('Could not send E-Mail');
      });
  }
github geli-lms / geli / api / src / models / Task.ts View on Github external
.catch((err: Error) => {
      const newError = new InternalServerError('Failed to import task');
      newError.stack += '\nCaused by: ' + err.message + '\n' + err.stack;
      throw newError;
    });
}
github geli-lms / geli / api / src / controllers / AuthController.ts View on Github external
throw new HttpError(503, errorCodes.errorCodes.user.retryAfter.code);
        }

        const existingUser = await User.findOne({email: email});
        if (existingUser && existingUser.uid !== uid) {
          throw new BadRequestError(errorCodes.errorCodes.mail.duplicate.code);
        }

        user.authenticationToken = undefined;
        user.email = email;
        const savedUser = await user.save();

        try {
          await emailService.resendActivation(savedUser);
        } catch (err) {
          throw new InternalServerError(err.toString());
        }
  }
github geli-lms / geli / api / src / controllers / DuplicationController.ts View on Github external
async duplicateLecture(@Param('id') id: string, @Body() data: any, @Req() request: Request) {
    const courseId = data.courseId;
    try {
      const lectureModel: ILectureModel = await Lecture.findById(id);
      const exportedLecture: ILecture = await lectureModel.exportJSON();
      return Lecture.schema.statics.importJSON(exportedLecture, courseId);
    } catch (err) {
      const newError = new InternalServerError('Failed to duplicate lecture');
      newError.stack += '\nCaused by: ' + err.message + '\n' + err.stack;
      throw newError;
    }
  }