mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
* progress on better error handling * wiring onError callback through module loader and resolver * fix error callbacks not being stored * update onError to be record * type alias * wiring * seems to work * update error handling contract and wire more * add command error builder * fix merge * progress on error handling * naive onError handling, not tested * progres * proress * progress on abstracting away iti * seems to work * fix tests * better typings * add doc * abstracting iti * remove onerror for this pr * feat: better way to add dependencies * fix tests
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import type { ReplyOptions } from "../../types/utility";
|
|
import type { Logging } from "../contracts";
|
|
|
|
export interface Response {
|
|
type: 'fail' | 'continue';
|
|
body?: ReplyOptions;
|
|
log?: { type: keyof Logging; message: unknown }
|
|
}
|
|
|
|
export const of = () => {
|
|
const payload = {
|
|
type: 'fail',
|
|
body: undefined,
|
|
log : undefined
|
|
} as Record<PropertyKey, unknown>
|
|
|
|
return {
|
|
/**
|
|
* @param {'fail' | 'continue'} p a status to determine if the error will
|
|
* terminate your application or continue. Warning and
|
|
*/
|
|
status: (p: 'fail' | 'continue') => {
|
|
payload.type = p;
|
|
return payload;
|
|
},
|
|
/**
|
|
* @param {keyof Logging} type Determine to log to logger[type].
|
|
* @param {T} message the message to log
|
|
*
|
|
* Log this error with the logger.
|
|
*/
|
|
log: <T=string>(type: keyof Logging, message: T) => {
|
|
payload.log = { type, message };
|
|
return payload;
|
|
},
|
|
reply: (bodyContent: ReplyOptions) => {
|
|
payload.body = bodyContent;
|
|
return payload;
|
|
}
|
|
};
|
|
}
|