/
errors.ts
80 lines (64 loc) · 2.14 KB
/
errors.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
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
// based on ApolloError https://github.com/apollographql/apollo-server/blob/main/packages/apollo-server-errors/src/index.ts
import { GraphQLError } from 'graphql'
export class RedwoodGraphQLError extends GraphQLError {
constructor(
message: string,
extensions?: Record<string, any>,
originalError?: Error & {
readonly extensions?: unknown
},
) {
super(message, {
extensions: {
...extensions,
code: extensions?.code || 'REDWOODJS_ERROR',
},
originalError,
})
Object.setPrototypeOf(this, GraphQLError.prototype)
}
}
export class SyntaxError extends RedwoodGraphQLError {
constructor(message: string) {
super(message, { code: 'GRAPHQL_PARSE_FAILED' })
Object.setPrototypeOf(this, SyntaxError.prototype)
}
}
export class ValidationError extends RedwoodGraphQLError {
constructor(message: string) {
super(message, { code: 'GRAPHQL_VALIDATION_FAILED' })
Object.setPrototypeOf(this, ValidationError.prototype)
}
}
export class AuthenticationError extends RedwoodGraphQLError {
constructor(message: string) {
super(message, { code: 'UNAUTHENTICATED' })
Object.setPrototypeOf(this, AuthenticationError.prototype)
}
}
export class ForbiddenError extends RedwoodGraphQLError {
constructor(message: string) {
super(message, { code: 'FORBIDDEN' })
Object.setPrototypeOf(this, ForbiddenError.prototype)
}
}
export class PersistedQueryNotFoundError extends RedwoodGraphQLError {
constructor() {
super('PersistedQueryNotFound', { code: 'PERSISTED_QUERY_NOT_FOUND' })
Object.setPrototypeOf(this, PersistedQueryNotFoundError.prototype)
}
}
export class PersistedQueryNotSupportedError extends RedwoodGraphQLError {
constructor() {
super('PersistedQueryNotSupported', {
code: 'PERSISTED_QUERY_NOT_SUPPORTED',
})
Object.setPrototypeOf(this, PersistedQueryNotSupportedError.prototype)
}
}
export class UserInputError extends RedwoodGraphQLError {
constructor(message: string, properties?: Record<string, any>) {
super(message, { code: 'BAD_USER_INPUT', properties })
Object.setPrototypeOf(this, UserInputError.prototype)
}
}