import { isObject } from '../helper/index.js';
export { createDefaultMiddlewareFailureBody, } from './MiddlewareFailureBody.js';
export const defaultMiddlewareFailureResponder = (_req, res, context) => {
    const statusTarget = res.setStatus(context.statusCode);
    const responseTarget = isObject(statusTarget) ? statusTarget : res;
    if (typeof responseTarget.json === 'function') {
        responseTarget.json(context.body);
        return;
    }
    if (typeof responseTarget.send === 'function') {
        responseTarget.send(JSON.stringify(context.body));
    }
};
export const respondWithMiddlewareFailure = async (req, res, responder, context) => {
    await (responder ?? defaultMiddlewareFailureResponder)(req, res, context);
};
