Files
outline/server/api/middlewares/apiWrapper.js

23 lines
397 B
JavaScript

// @flow
import { type Context } from 'koa';
export default function apiWrapper() {
return async function apiWrapperMiddleware(
ctx: Context,
next: () => Promise<*>
) {
await next();
const ok = ctx.status < 400;
if (typeof ctx.body !== 'string') {
// $FlowFixMe
ctx.body = {
...ctx.body,
status: ctx.status,
ok,
};
}
};
}