minauth
Version:
A TypeScript library for building authentication systems on top of the Mina blockchain and other zero-knowledge proofs solutions.
14 lines • 782 B
JavaScript
import { pipe } from 'fp-ts/lib/function.js';
import * as T from 'fp-ts/lib/Task.js';
import * as TE from 'fp-ts/lib/TaskEither.js';
/**
* Converts a simple request handler from a functional-style definition
* into a form expected by express.js
* If the handler returns a value, it is returned as json with code 200
* If the handler throws an error, it is logged and the code 400 is returned
*/
export const wrapTrivialExpressHandler = (f, onError = (err) => ({ statusCode: 400, body: { error: err } })) => (req, resp) => pipe(f(req), TE.tapIO((result) => () => resp.status(200).json(result)), TE.tapError((error) => TE.fromIO(() => {
const { statusCode, body } = onError(error);
resp.status(statusCode).json(body);
})), T.asUnit)();
//# sourceMappingURL=express.js.map