- ✅ Ticket 1.1: Estructura Clean Architecture en backend - ✅ Ticket 1.2: Schemas Zod compartidos - ✅ Ticket 1.3: Refactorización drugs.ts (1362 → 8 archivos modulares) - ✅ Ticket 1.4: Refactorización procedures.ts (3583 → 6 archivos modulares) - ✅ Ticket 1.5: Eliminación de duplicidades (~50 líneas) Cambios principales: - Creada estructura Clean Architecture en backend/src/ - Schemas Zod compartidos en backend/src/shared/schemas/ - Refactorización modular de drugs y procedures - Utilidades genéricas en src/utils/ (filter, validation) - Eliminados scripts obsoletos y documentación antigua - Corregidos errores: QueryClient, import test-error-handling - Build verificado y funcionando correctamente
42 lines
1 KiB
JavaScript
42 lines
1 KiB
JavaScript
// @ts-expect-error
|
|
import formatter from 'format'
|
|
|
|
export const fault = Object.assign(create(Error), {
|
|
eval: create(EvalError),
|
|
range: create(RangeError),
|
|
reference: create(ReferenceError),
|
|
syntax: create(SyntaxError),
|
|
type: create(TypeError),
|
|
uri: create(URIError)
|
|
})
|
|
|
|
/**
|
|
* Create a new `EConstructor`, with the formatted `format` as a first argument.
|
|
*
|
|
* @template {Error} Fault
|
|
* @template {new (reason: string) => Fault} Class
|
|
* @param {Class} Constructor
|
|
*/
|
|
export function create(Constructor) {
|
|
/** @type {string} */
|
|
// @ts-expect-error
|
|
FormattedError.displayName = Constructor.displayName || Constructor.name
|
|
|
|
return FormattedError
|
|
|
|
/**
|
|
* Create an error with a printf-like formatted message.
|
|
*
|
|
* @param {string|null} [format]
|
|
* Template string.
|
|
* @param {...unknown} values
|
|
* Values to render in `format`.
|
|
* @returns {Fault}
|
|
*/
|
|
function FormattedError(format, ...values) {
|
|
/** @type {string} */
|
|
const reason = format ? formatter(format, ...values) : format
|
|
return new Constructor(reason)
|
|
}
|
|
}
|