|
| 1 | +import { Code, ConnectError } from '@connectrpc/connect'; |
| 2 | + |
| 3 | +// Non-retryable ConnectError codes |
| 4 | +export const unauthenticatedError = new ConnectError( |
| 5 | + 'User is not authenticated', |
| 6 | + Code.Unauthenticated |
| 7 | +); |
| 8 | + |
| 9 | +export const permissionDeniedError = new ConnectError( |
| 10 | + 'Permission denied to access resource', |
| 11 | + Code.PermissionDenied |
| 12 | +); |
| 13 | + |
| 14 | +export const invalidArgumentError = new ConnectError( |
| 15 | + 'Invalid argument provided', |
| 16 | + Code.InvalidArgument |
| 17 | +); |
| 18 | + |
| 19 | +export const notFoundError = new ConnectError( |
| 20 | + 'Resource not found', |
| 21 | + Code.NotFound |
| 22 | +); |
| 23 | + |
| 24 | +export const failedPreconditionError = new ConnectError( |
| 25 | + 'Failed precondition check', |
| 26 | + Code.FailedPrecondition |
| 27 | +); |
| 28 | + |
| 29 | +export const outOfRangeError = new ConnectError( |
| 30 | + 'Value out of range', |
| 31 | + Code.OutOfRange |
| 32 | +); |
| 33 | + |
| 34 | +export const unimplementedError = new ConnectError( |
| 35 | + 'Method not implemented', |
| 36 | + Code.Unimplemented |
| 37 | +); |
| 38 | + |
| 39 | +export const alreadyExistsError = new ConnectError( |
| 40 | + 'Resource already exists', |
| 41 | + Code.AlreadyExists |
| 42 | +); |
| 43 | + |
| 44 | +export const canceledError = new ConnectError( |
| 45 | + 'Operation was canceled', |
| 46 | + Code.Canceled |
| 47 | +); |
| 48 | + |
| 49 | +// Retryable ConnectError codes |
| 50 | +export const unavailableError = new ConnectError( |
| 51 | + 'Service unavailable', |
| 52 | + Code.Unavailable |
| 53 | +); |
| 54 | + |
| 55 | +export const deadlineExceededError = new ConnectError( |
| 56 | + 'Deadline exceeded', |
| 57 | + Code.DeadlineExceeded |
| 58 | +); |
| 59 | + |
| 60 | +export const abortedError = new ConnectError('Operation aborted', Code.Aborted); |
| 61 | + |
| 62 | +export const internalError = new ConnectError( |
| 63 | + 'Internal server error', |
| 64 | + Code.Internal |
| 65 | +); |
| 66 | + |
| 67 | +export const unknownError = new ConnectError( |
| 68 | + 'Unknown error occurred', |
| 69 | + Code.Unknown |
| 70 | +); |
| 71 | + |
| 72 | +// Non-retryable standard errors |
| 73 | +export const configurationError = new Error('Invalid configuration provided'); |
| 74 | + |
| 75 | +export const cannotDialError = new Error( |
| 76 | + 'cannot dial "example.com" directly, please use a local url instead.' |
| 77 | +); |
| 78 | + |
| 79 | +// Retryable standard errors |
| 80 | +export const networkError = new Error('Network connection failed'); |
| 81 | + |
| 82 | +export const timeoutError = new Error('Connection timed out'); |
0 commit comments