add types for errors

This commit is contained in:
Elliot DeNolf
2020-11-23 22:43:35 -05:00
parent badd59ac38
commit 6fcf4ebc48
9 changed files with 22 additions and 8 deletions

View File

@@ -5,6 +5,14 @@ import httpStatus from 'http-status';
* @extends Error
*/
class ExtendableError extends Error {
status: number;
data: any;
isPublic: boolean;
isOperational: boolean;
constructor(message: string, status: number, data: any, isPublic: boolean) {
super(message);
this.name = this.constructor.name;
@@ -13,6 +21,8 @@ class ExtendableError extends Error {
this.data = data;
this.isPublic = isPublic;
this.isOperational = true; // This is required since bluebird 4 doesn't append it anymore.
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore Couldn't get the compiler to love me
Error.captureStackTrace(this, this.constructor.name);
}
}

View File

@@ -1,7 +1,7 @@
import APIError from './APIError';
class DuplicateCollection extends APIError {
constructor(propertyName, duplicates) {
constructor(propertyName: string, duplicates: string[]) {
super(`Collection ${propertyName} already in use: "${duplicates.join(', ')}"`);
}
}

View File

@@ -1,7 +1,8 @@
import { Global } from '../globals/config/types';
import APIError from './APIError';
class DuplicateGlobal extends APIError {
constructor(config) {
constructor(config: Global) {
super(`Global label "${config.label}" is already in use`);
}
}

View File

@@ -2,7 +2,7 @@ import httpStatus from 'http-status';
import APIError from './APIError';
class InvalidConfiguration extends APIError {
constructor(message, results?) {
constructor(message: string, results: any) {
super(message, httpStatus.INTERNAL_SERVER_ERROR, results);
}
}

View File

@@ -2,7 +2,7 @@ import httpStatus from 'http-status';
import APIError from './APIError';
class InvalidSchema extends APIError {
constructor(message, results) {
constructor(message: string, results: any) {
super(message, httpStatus.INTERNAL_SERVER_ERROR, results);
}
}

View File

@@ -1,7 +1,8 @@
import { Field } from '../fields/config/types';
import APIError from './APIError';
class MissingFieldInputOptions extends APIError {
constructor(field) {
constructor(field: Field) {
super(`Field ${field.label} is missing options.`);
}
}

View File

@@ -1,7 +1,8 @@
import { Field } from '../fields/config/types';
import APIError from './APIError';
class MissingFieldType extends APIError {
constructor(field) {
constructor(field: Field) {
super(`Field "${field.name}" is either missing a field type or it does not match an available field type`);
}
}

View File

@@ -1,7 +1,8 @@
import { Config } from '../config/types';
import APIError from './APIError';
class MissingGlobalLabel extends APIError {
constructor(config) {
constructor(config: Config) {
super(`${config.globals} object is missing label`);
}
}

View File

@@ -2,7 +2,7 @@ import httpStatus from 'http-status';
import APIError from './APIError';
class ValidationError extends APIError {
constructor(results) {
constructor(results: any[]) {
super(`Bad request with ${results.length} errors`, httpStatus.BAD_REQUEST, results);
}
}