Files
gridpilot.gg/apps/website/lib/contracts/mutations/MutationError.ts
2026-01-14 10:51:05 +01:00

50 lines
1.5 KiB
TypeScript

/**
* Mutation Error Type
*
* Errors that can be handled by the client after a mutation.
* These are mapped from DomainErrors by Mutations.
*/
export type MutationError =
| 'userNotFound' // User doesn't exist
| 'noPermission' // Insufficient permissions
| 'invalidData' // Validation failed
| 'updateFailed' // Update operation failed
| 'deleteFailed' // Delete operation failed
| 'createFailed' // Create operation failed
| 'networkError' // Network/communication error
| 'serverError' // Generic server error
| 'notImplemented' // Feature not implemented
| 'unknown'; // Unknown error
// Helper to map DomainError to MutationError
export function mapToMutationError(domainError: any): MutationError {
const errorType = domainError?.type || domainError?.name || 'unknown';
switch (errorType) {
case 'notFound':
case 'NotFoundError':
case 'userNotFound':
return 'userNotFound';
case 'unauthorized':
case 'UnauthorizedError':
case 'ForbiddenError':
return 'noPermission';
case 'validationError':
case 'ValidationError':
return 'invalidData';
case 'serverError':
case 'ServerError':
case 'HttpServerError':
return 'serverError';
case 'networkError':
case 'NetworkError':
return 'networkError';
case 'notImplemented':
case 'NotImplementedError':
return 'notImplemented';
default:
return 'unknown';
}
}