UNPKG

@upv/ushi-shared

Version:

Shared DTOs, types, and utilities for the USHI platform (LMS, Trials, Social, Wallet).

26 lines (25 loc) 1.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.internalError = exports.badRequest = exports.conflict = exports.validationFailed = exports.notFound = exports.forbidden = exports.unauthorized = void 0; const errorResponse_1 = require("./errorResponse"); const errors_1 = require("../errors"); const unauthorized = (message = 'Unauthorized', context) => (0, errorResponse_1.error)(errors_1.ApiErrorCode.UNAUTHORIZED, message, 401, context); exports.unauthorized = unauthorized; const forbidden = (message = 'Forbidden', context) => (0, errorResponse_1.error)(errors_1.ApiErrorCode.FORBIDDEN, message, 403, context); exports.forbidden = forbidden; const notFound = (message = 'Not Found', context) => (0, errorResponse_1.error)(errors_1.ApiErrorCode.NOT_FOUND, message, 404, context); exports.notFound = notFound; const validationFailed = (message = 'Validation failed', context) => (0, errorResponse_1.error)(errors_1.ApiErrorCode.VALIDATION_FAILED, message, 400, context); exports.validationFailed = validationFailed; const conflict = (message = 'Conflict', context) => (0, errorResponse_1.error)(errors_1.ApiErrorCode.CONFLICT, message, 409, context); exports.conflict = conflict; const badRequest = (message = 'Bad request', context) => (0, errorResponse_1.error)(errors_1.ApiErrorCode.BAD_REQUEST, message, 400, context); exports.badRequest = badRequest; const internalError = (err, fallbackMessage = 'An unexpected error occurred') => { const message = err instanceof Error ? err.message : fallbackMessage; const stack = err instanceof Error ? err.stack : undefined; return (0, errorResponse_1.error)(errors_1.ApiErrorCode.INTERNAL_ERROR, message, 500, { ...(stack ? { stack } : {}), }); }; exports.internalError = internalError;