-
Notifications
You must be signed in to change notification settings - Fork 486
Expand file tree
/
Copy patherrors.ts
More file actions
33 lines (29 loc) · 802 Bytes
/
errors.ts
File metadata and controls
33 lines (29 loc) · 802 Bytes
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
/**
* Shared error helper utilities for tests.
* These provide typed ways to create errors with additional properties
* like `code` (for Node.js filesystem errors) and `constraint` (for Postgres errors).
*/
export interface NodeError extends Error {
code?: string
}
export interface PostgresError extends Error {
code: string
constraint?: string
}
export const createNodeError = (message: string, code: string): NodeError => {
const error: NodeError = new Error(message)
error.code = code
return error
}
export const createPostgresError = (
message: string,
code: string,
constraint?: string,
): PostgresError => {
const error = new Error(message) as PostgresError
error.code = code
if (constraint !== undefined) {
error.constraint = constraint
}
return error
}