Skip to content

@univ-lehavre/atlas-errors ​

Shared error classes for Atlas applications.

About ​

This package provides standardized error classes for Atlas applications, with error codes, HTTP statuses, and conversion to structured API responses.

Features ​

  • Typed errors: Error classes with codes and HTTP statuses
  • Authentication errors: SessionError, MagicUrlLoginValidationError
  • Validation errors: InvalidJsonBodyError, InvalidContentTypeError, NotAnEmailError
  • API mapping: Automatic conversion to standardized JSON responses

Installation ​

bash
pnpm add @univ-lehavre/atlas-errors

Usage ​

typescript
import {
  SessionError,
  InvalidJsonBodyError,
  InvalidContentTypeError,
  NotAnEmailError,
  mapErrorToApiResponse,
} from '@univ-lehavre/atlas-errors';

// Throw a typed error
if (!session) {
  throw new SessionError('No active session', { cause: 'Cookie expired' });
}

// Convert an error to API response
try {
  // ... operation
} catch (error) {
  const { body, status } = mapErrorToApiResponse(error);
  return json(body, { status });
}

API ​

Error Classes ​

ClassHTTP CodeDescription
SessionError401Missing or invalid session
InvalidJsonBodyError400Invalid JSON request body
InvalidContentTypeError400Content-Type not application/json
NotAnEmailError400Invalid or unauthorized email
NotPartOfAllianceError400Unauthorized email domain
MagicUrlLoginValidationError400Invalid magic URL parameters
UserIdValidationError400Invalid user ID
RequestBodyValidationError400Invalid request body

Functions ​

FunctionDescription
mapErrorToApiResponse(error)Converts an error to a structured API response

Scripts ​

bash
pnpm -F @univ-lehavre/atlas-errors dev      # Development
pnpm -F @univ-lehavre/atlas-errors build    # Build
pnpm -F @univ-lehavre/atlas-errors test     # Tests
pnpm -F @univ-lehavre/atlas-errors lint     # ESLint

Documentation ​

Organization ​

This package is part of Atlas, a set of tools developed by Le Havre Normandie University to facilitate research and collaboration between researchers.

Atlas is developed as part of two projects led by Le Havre Normandie University:


Le Havre Normandie University     Campus Polytechnique des Territoires Maritimes et Portuaires     EUNICoast

License ​

MIT

Modules ​

ModuleDescription
-
auth-