Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 45 46 47 48 49 50 51 52 | 3x | export type ApiErrorType =
| "bad-request"
| "internal"
| "not-allowed"
| "not-with-children"
| "not-unique";
export const API_ERROR_TYPE = {
BAD_REQUEST: "bad-request" as ApiErrorType,
INTERNAL: "internal" as ApiErrorType,
NULL_DISALLOWED: "null-disallowed" as ApiErrorType,
NOT_ALLOWED: "not-allowed" as ApiErrorType,
NOT_UNIQUE: "not-unique" as ApiErrorType,
NOT_WITH_CHILDREN: "not-with-children" as ApiErrorType,
};
export class ApiError {
transportError: number;
message: string;
errorType: ApiErrorType;
constructor(errorType: ApiErrorType, message: string) {
this.transportError = this.evaluateType(errorType);
this.errorType = errorType;
this.message = message;
}
private evaluateType(errorType: ApiErrorType) {
switch (errorType) {
case API_ERROR_TYPE.BAD_REQUEST:
return 400;
case API_ERROR_TYPE.BAD_REQUEST:
return 401;
case API_ERROR_TYPE.INTERNAL:
return 500;
case API_ERROR_TYPE.NOT_UNIQUE:
return 409;
case API_ERROR_TYPE.NOT_WITH_CHILDREN:
return 409;
case API_ERROR_TYPE.NOT_ALLOWED:
return 401;
}
return 500;
}
}
|