-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrors.ts
More file actions
87 lines (78 loc) · 2.27 KB
/
Copy patherrors.ts
File metadata and controls
87 lines (78 loc) · 2.27 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import * as t from 'io-ts';
/**
* Custom error classes for specific error types
*/
/**
* Base custom error class with common setup
*/
export class BitgoExpressError extends Error {
constructor(message: string, name: string) {
super(message);
this.name = name;
Object.setPrototypeOf(this, new.target.prototype);
}
}
/**
* ValidationError represents a client error due to invalid input parameters
* Should result in a 422 Unprocessable Entity HTTP status code
*/
export class ValidationError extends BitgoExpressError {
constructor(message: string) {
super(message, 'ValidationError');
}
}
/**
* NotFoundError represents a resource that could not be found
* Should result in a 404 Not Found HTTP status code
*/
export class NotFoundError extends BitgoExpressError {
constructor(message: string) {
super(message, 'NotFoundError');
}
}
/**
* BadRequestError represents a client error due to invalid request format
* Should result in a 400 Bad Request HTTP status code
*/
export class BadRequestError extends BitgoExpressError {
constructor(message: string) {
super(message, 'BadRequestError');
}
}
/**
* UnauthorizedError represents an authentication failure
* Should result in a 401 Unauthorized HTTP status code
*/
export class UnauthorizedError extends BitgoExpressError {
constructor(message: string) {
super(message, 'UnauthorizedError');
}
}
/**
* ForbiddenError represents an authorization failure
* Should result in a 403 Forbidden HTTP status code
*/
export class ForbiddenError extends BitgoExpressError {
constructor(message: string) {
super(message, 'ForbiddenError');
}
}
/**
* ConflictError represents a conflict with the current state of the resource
* Should result in a 409 Conflict HTTP status code
*/
export class ConflictError extends BitgoExpressError {
constructor(message: string) {
super(message, 'ConflictError');
}
}
// Define specific HTTP error responses
// Common error response types
const ErrorResponse = t.type({
error: t.string,
details: t.string,
});
export const BadRequestResponse = { 400: ErrorResponse };
export const UnprocessableEntityResponse = { 422: ErrorResponse };
export const InternalServerErrorResponse = { 500: ErrorResponse };
export const NotFoundResponse = { 404: ErrorResponse };