Add missing API error class exports/imports

This commit is contained in:
Maciej Ziarkowski 2020-01-29 17:24:04 +00:00
parent 92ff5d7172
commit 899e450eda
3 changed files with 10 additions and 5 deletions

View File

@ -2,6 +2,7 @@ import bodyParser from 'body-parser';
import express from 'express'; import express from 'express';
import * as editHistoryController from './controllers/editHistoryController'; import * as editHistoryController from './controllers/editHistoryController';
import { RequestParameterError, UserInputError } from './errors';
import buildingsRouter from './routes/buildingsRouter'; import buildingsRouter from './routes/buildingsRouter';
import extractsRouter from './routes/extractsRouter'; import extractsRouter from './routes/extractsRouter';
import usersRouter from './routes/usersRouter'; import usersRouter from './routes/usersRouter';

View File

@ -5,13 +5,13 @@
* https://stackoverflow.com/questions/41102060/typescript-extending-error-class * https://stackoverflow.com/questions/41102060/typescript-extending-error-class
*/ */
class UserInputError extends Error { export class UserInputError extends Error {
constructor(message?: string) { constructor(message?: string) {
super(message); super(message);
} }
} }
class RequestParameterError extends UserInputError { export class RequestParameterError extends UserInputError {
public paramName: string; public paramName: string;
constructor(message?: string) { constructor(message?: string) {
@ -19,19 +19,19 @@ class RequestParameterError extends UserInputError {
} }
} }
class ParamRequiredError extends RequestParameterError { export class ParamRequiredError extends RequestParameterError {
constructor(message?: string) { constructor(message?: string) {
super(message); super(message);
} }
} }
class ParamOutOfBoundsError extends RequestParameterError { export class ParamOutOfBoundsError extends RequestParameterError {
constructor(message?: string) { constructor(message?: string) {
super(message); super(message);
} }
} }
class ParamInvalidFormatError extends RequestParameterError { export class ParamInvalidFormatError extends RequestParameterError {
constructor(message?: string) { constructor(message?: string) {
super(message); super(message);
} }

View File

@ -1,5 +1,7 @@
import { strictParseInt } from '../parse'; import { strictParseInt } from '../parse';
import { ParamInvalidFormatError, ParamRequiredError, RequestParameterError } from './errors';
export function processParam<T>(params: object, paramName: string, processingFn: (x: string) => T, required: boolean = false) { export function processParam<T>(params: object, paramName: string, processingFn: (x: string) => T, required: boolean = false) {
const stringValue = params[paramName]; const stringValue = params[paramName];
@ -37,4 +39,6 @@ export function checkRegexParam(param: string, regex: RegExp): string {
if(param.match(regex) == undefined) { if(param.match(regex) == undefined) {
throw new ParamInvalidFormatError(`Invalid format: does not match regular expression ${regex}`); throw new ParamInvalidFormatError(`Invalid format: does not match regular expression ${regex}`);
} }
return param;
} }