-
Notifications
You must be signed in to change notification settings - Fork 821
/
errors.js
42 lines (36 loc) · 1.3 KB
/
errors.js
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
import { createError } from 'apollo-errors';
export const LEVEL_WARNING = 'warning';
export const LEVEL_ERROR = 'error';
export const TYPE_AUTH = 'authentication';
export const TYPE_TECHNICAL = 'technical';
const TYPE_BUSINESS = 'business';
// TYPE_BUSINESS
export const AuthenticationFailure = createError('AuthenticationFailure', {
message: 'Wrong name or password',
data: { type: TYPE_BUSINESS, level: LEVEL_WARNING }
});
export const buildValidationError = field => {
const ErrorType = createError('Functional', {
message: `Validation error for ${field}`,
data: { type: TYPE_BUSINESS, level: LEVEL_ERROR }
});
return new ErrorType();
};
// TYPE_AUTH
export const AuthRequired = createError('AuthRequired', {
message: 'You must be logged in to do this.',
data: { type: TYPE_AUTH, level: LEVEL_WARNING }
});
export const ForbiddenAccess = createError('ForbiddenAccess', {
message: 'You are not allowed to do this.',
data: { type: TYPE_AUTH, level: LEVEL_WARNING }
});
// TYPE_TECHNICAL
export const DatabaseError = createError('DatabaseError', {
message: 'A database error has occured!',
data: { type: TYPE_TECHNICAL }
});
export const Unknown = createError('Unknown', {
message: 'An unknown error has occurred! Please try again later.',
data: { type: TYPE_TECHNICAL, level: LEVEL_ERROR }
});