diff --git a/koa-json-error/koa-json-error-tests.ts b/koa-json-error/koa-json-error-tests.ts new file mode 100644 index 0000000000..37aae696b0 --- /dev/null +++ b/koa-json-error/koa-json-error-tests.ts @@ -0,0 +1,13 @@ +/// +/// +/// + +import * as Koa from "koa"; +import * as error from "koa-json-error"; +import { assign } from "lodash"; + +const app = new Koa(); + +app.use(error({ + preFormat: err => assign({}, err) +})); \ No newline at end of file diff --git a/koa-json-error/koa-json-error.d.ts b/koa-json-error/koa-json-error.d.ts new file mode 100644 index 0000000000..491ead463e --- /dev/null +++ b/koa-json-error/koa-json-error.d.ts @@ -0,0 +1,36 @@ +// Type definitions for koa-json-error v3.x +// Project: https://github.com/koajs/json-error +// Definitions by: Mudkip +// Definitions: https://github.com/mudkipme/DefinitelyTyped + +/// + +declare module "koa-json-error" { + + import * as Koa from "koa"; + + interface JSONErrorOptions { + /** + * Perform some task before calling `options.format`. Must be a function with the original err as its only argument. + */ + preFormat?: { (err: Error): any }; + + /** + * Runs inmediatly after `options.preFormat`. It receives two arguments: the original `err` and the output of `options.preFormat`. It should `return` a newly formatted error. + */ + format?: { (err: Error, obj: any): any }; + + /** + * Runs inmediatly after `options.format`. It receives two arguments: the original `err` and the output of `options.format`. It should `return` a newly formatted error. + */ + postFormat?: { (err: Error, obj: any): any }; + } + + /** + * Error handler for pure Koa 2.0.0+ JSON apps + */ + function jsonError(options?: JSONErrorOptions) : { (ctx: Koa.Context, next?: () => any): any }; + + namespace jsonError {} + export = jsonError; +} \ No newline at end of file