add types for errors
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(', ')}"`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user