How to use the @stoplight/prism-http.ProblemJsonError.fromPlainError function in @stoplight/prism-http

To help you get started, we’ve selected a few @stoplight/prism-http examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stoplightio / prism / packages / http-server / src / server.ts View on Github external
TE.mapLeft((e: Error & { status?: number; additional?: { headers?: Dictionary } }) => {
        if (!reply.sent) {
          const status = e.status || 500;
          reply
            .type('application/problem+json')
            .serializer(JSON.stringify)
            .code(status);

          if (e.additional && e.additional.headers) {
            reply.headers(e.additional.headers);
          }

          reply.send(ProblemJsonError.fromPlainError(e));
        } else {
          reply.res.end();
        }

        request.log.error({ input }, `Request terminated with error: ${e}`);
      })
    )();