import { InvalidArgumentError } from '@og/error-utils'; /** @typedef {import('koa').Context} Context */ /** @typedef {import('koa').Next} Next */ /** * @param {Context} ctx * @param {Next} next */ export async function errorAsResponse(ctx, next) { try { await next(); } catch (err) { if (err instanceof InvalidArgumentError) { ctx.status = 400; ctx.body = { error: err.toString(), errno: 'EIA' }; } else { ctx.status = 500; throw err; } } };