forked from atlassian/oas3-chow-chow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.ts
44 lines (38 loc) · 1.18 KB
/
error.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { IOutputError } from 'better-ajv-errors';
export interface ChowErrorMeta {
in: string;
rawErrors?: IOutputError[];
code?: number;
}
export default class ChowError extends Error {
meta: ChowErrorMeta;
constructor(message: string, meta: ChowErrorMeta) {
// Pass remaining arguments (including vendor specific ones) to parent constructor
super(message);
this.name = this.constructor.name;
// Custom debugging information
this.meta = meta;
}
public toJSON() {
return {
code: this.meta.code || 400,
location: {
in: this.meta.in,
},
message: this.message,
suggestions: this.meta.rawErrors || [],
};
}
}
export class RequestValidationError extends ChowError {
constructor(message: string, meta: ChowErrorMeta) {
// Pass remaining arguments (including vendor specific ones) to parent constructor
super(`RequestValidationError: ${message}`, meta);
}
}
export class ResponseValidationError extends ChowError {
constructor(message: string, meta: ChowErrorMeta) {
// Pass remaining arguments (including vendor specific ones) to parent constructor
super(`ResponseValidationError: ${message}`, meta);
}
}