This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
2017-11-16 06:56:40 +00:00
|
|
|
// @flow
|
|
|
|
import { type Context } from 'koa';
|
|
|
|
|
|
|
|
export default function apiWrapper() {
|
|
|
|
return async function apiWrapperMiddleware(
|
|
|
|
ctx: Context,
|
|
|
|
next: () => Promise<void>
|
|
|
|
) {
|
2016-09-11 20:38:52 +00:00
|
|
|
await next();
|
|
|
|
|
2016-09-11 22:48:03 +00:00
|
|
|
const ok = ctx.status < 400;
|
2016-09-11 20:38:52 +00:00
|
|
|
|
2017-11-16 06:56:40 +00:00
|
|
|
// $FlowFixMe
|
2016-09-11 20:38:52 +00:00
|
|
|
ctx.body = {
|
|
|
|
...ctx.body,
|
2016-09-17 21:53:30 +00:00
|
|
|
status: ctx.status,
|
2016-09-11 22:48:03 +00:00
|
|
|
ok,
|
2016-09-11 20:38:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|