From 899e450edae6d85e01ef693dca70aab2e7a8eb28 Mon Sep 17 00:00:00 2001 From: Maciej Ziarkowski Date: Wed, 29 Jan 2020 17:24:04 +0000 Subject: [PATCH] Add missing API error class exports/imports --- app/src/api/api.ts | 1 + app/src/api/errors.ts | 10 +++++----- app/src/api/parameters.ts | 4 ++++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/api/api.ts b/app/src/api/api.ts index cb6a95e9..79458ee5 100644 --- a/app/src/api/api.ts +++ b/app/src/api/api.ts @@ -2,6 +2,7 @@ import bodyParser from 'body-parser'; import express from 'express'; import * as editHistoryController from './controllers/editHistoryController'; +import { RequestParameterError, UserInputError } from './errors'; import buildingsRouter from './routes/buildingsRouter'; import extractsRouter from './routes/extractsRouter'; import usersRouter from './routes/usersRouter'; diff --git a/app/src/api/errors.ts b/app/src/api/errors.ts index 5d3eb475..e1d1bd35 100644 --- a/app/src/api/errors.ts +++ b/app/src/api/errors.ts @@ -5,13 +5,13 @@ * https://stackoverflow.com/questions/41102060/typescript-extending-error-class */ -class UserInputError extends Error { +export class UserInputError extends Error { constructor(message?: string) { super(message); } } -class RequestParameterError extends UserInputError { +export class RequestParameterError extends UserInputError { public paramName: string; constructor(message?: string) { @@ -19,19 +19,19 @@ class RequestParameterError extends UserInputError { } } -class ParamRequiredError extends RequestParameterError { +export class ParamRequiredError extends RequestParameterError { constructor(message?: string) { super(message); } } -class ParamOutOfBoundsError extends RequestParameterError { +export class ParamOutOfBoundsError extends RequestParameterError { constructor(message?: string) { super(message); } } -class ParamInvalidFormatError extends RequestParameterError { +export class ParamInvalidFormatError extends RequestParameterError { constructor(message?: string) { super(message); } diff --git a/app/src/api/parameters.ts b/app/src/api/parameters.ts index 612eef82..0146dc97 100644 --- a/app/src/api/parameters.ts +++ b/app/src/api/parameters.ts @@ -1,5 +1,7 @@ import { strictParseInt } from '../parse'; +import { ParamInvalidFormatError, ParamRequiredError, RequestParameterError } from './errors'; + export function processParam(params: object, paramName: string, processingFn: (x: string) => T, required: boolean = false) { const stringValue = params[paramName]; @@ -37,4 +39,6 @@ export function checkRegexParam(param: string, regex: RegExp): string { if(param.match(regex) == undefined) { throw new ParamInvalidFormatError(`Invalid format: does not match regular expression ${regex}`); } + + return param; }