* @template {{message: string}} T * @template {Omit } K * @param {import('types').Logger} log * @param {'fail' | 'warn' | 'ignore' | ((details: T) => void)} input * @param {(details: K) => string} format * @returns {(details: K) => void}
(log, input, format)
| 58 | * @returns {(details: K) => void} |
| 59 | */ |
| 60 | function normalise_error_handler(log, input, format) { |
| 61 | switch (input) { |
| 62 | case 'fail': |
| 63 | return (details) => { |
| 64 | throw new Error(format(details)); |
| 65 | }; |
| 66 | case 'warn': |
| 67 | return (details) => { |
| 68 | log.error(format(details)); |
| 69 | }; |
| 70 | case 'ignore': |
| 71 | return () => {}; |
| 72 | default: |
| 73 | // @ts-expect-error TS thinks T might be of a different kind, but it's not |
| 74 | return (details) => input({ ...details, message: format(details) }); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | const OK = 2; |
| 79 | const REDIRECT = 3; |