|
|
@ -1,3 +1,5 @@ |
|
|
|
|
|
|
|
import { ErrorObject } from 'ajv'; |
|
|
|
|
|
|
|
|
|
|
|
enum DBError { |
|
|
|
enum DBError { |
|
|
|
TABLE_EXIST = 'TABLE_EXIST', |
|
|
|
TABLE_EXIST = 'TABLE_EXIST', |
|
|
|
TABLE_NOT_EXIST = 'TABLE_NOT_EXIST', |
|
|
|
TABLE_NOT_EXIST = 'TABLE_NOT_EXIST', |
|
|
@ -409,6 +411,8 @@ export default function ( |
|
|
|
return res.status(500).json({ msg: e.message }); |
|
|
|
return res.status(500).json({ msg: e.message }); |
|
|
|
} else if (e instanceof NotImplemented) { |
|
|
|
} else if (e instanceof NotImplemented) { |
|
|
|
return res.status(501).json({ msg: e.message }); |
|
|
|
return res.status(501).json({ msg: e.message }); |
|
|
|
|
|
|
|
} else if (e instanceof AjvError) { |
|
|
|
|
|
|
|
return res.status(501).json({ msg: e.message, errors: e.errors }); |
|
|
|
} |
|
|
|
} |
|
|
|
next(e); |
|
|
|
next(e); |
|
|
|
} |
|
|
|
} |
|
|
@ -427,6 +431,15 @@ class InternalServerError extends Error {} |
|
|
|
|
|
|
|
|
|
|
|
class NotImplemented extends Error {} |
|
|
|
class NotImplemented extends Error {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AjvError extends Error { |
|
|
|
|
|
|
|
constructor(param: { message: string; errors: ErrorObject[] }) { |
|
|
|
|
|
|
|
super(param.message); |
|
|
|
|
|
|
|
this.errors = param.errors; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
errors: ErrorObject[]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export class NcError { |
|
|
|
export class NcError { |
|
|
|
static notFound(message = 'Not found') { |
|
|
|
static notFound(message = 'Not found') { |
|
|
|
throw new NotFound(message); |
|
|
|
throw new NotFound(message); |
|
|
@ -451,4 +464,8 @@ export class NcError { |
|
|
|
static notImplemented(message = 'Not implemented') { |
|
|
|
static notImplemented(message = 'Not implemented') { |
|
|
|
throw new NotImplemented(message); |
|
|
|
throw new NotImplemented(message); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static ajvValidationError(param: { message: string; errors: ErrorObject[] }) { |
|
|
|
|
|
|
|
throw new AjvError(param); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|