Files
gridpilot.gg/apps/website/lib/contracts/page-queries/PresentationError.ts
2026-01-13 02:38:49 +01:00

43 lines
1.3 KiB
TypeScript

/**
* Presentation Error Type
*
* Errors that can be handled by the presentation layer (RSC pages, templates).
* These are mapped from DomainErrors by PageQueries.
*/
export type PresentationError =
| 'notFound' // Resource not found - show 404 page
| 'redirect' // Redirect to another page (e.g., login)
| 'unauthorized' // Not authorized - show access denied
| 'serverError' // Generic server error
| 'networkError' // Network/communication error
| 'validationError' // Invalid input data
| 'unknown'; // Unknown error
// Helper to map DomainError to PresentationError
export function mapToPresentationError(domainError: any): PresentationError {
const errorType = domainError?.type || domainError?.name || 'unknown';
switch (errorType) {
case 'notFound':
case 'NotFoundError':
return 'notFound';
case 'unauthorized':
case 'UnauthorizedError':
case 'ForbiddenError':
return 'unauthorized';
case 'serverError':
case 'ServerError':
case 'HttpServerError':
return 'serverError';
case 'networkError':
case 'NetworkError':
return 'networkError';
case 'validationError':
case 'ValidationError':
return 'validationError';
default:
return 'unknown';
}
}