UNPKG

kequapp

Version:

DEPRECATED: renamed to @kequtech/arbor

29 lines (28 loc) 1.06 kB
import { Ex } from "../../ex.js"; export function findRenderer(renderers, contentType) { const renderer = renderers.find((renderer) => compareContentType(renderer.contentType, contentType)); if (!renderer) { throw Ex.InternalServerError('Renderer not found', { contentType, availalble: renderers.map((renderer) => renderer.contentType), }); } return renderer.action; } export function findErrorHandler(errorHandlers, contentType) { const errorHandler = errorHandlers.find((errorHandler) => compareContentType(errorHandler.contentType, contentType)); if (!errorHandler) { throw Ex.InternalServerError('Error handler not found', { contentType, availalble: errorHandlers.map((errorHandler) => errorHandler.contentType), }); } return errorHandler.action; } function compareContentType(a, b) { const wildIndex = a.indexOf('*'); if (wildIndex > -1) { return a.slice(0, wildIndex) === b.slice(0, wildIndex); } return a === b; }