How to use the http-errors.UnprocessableEntity function in http-errors

To help you get started, we’ve selected a few http-errors 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 middyjs / middy / src / middlewares / __tests__ / httpErrorHandler.js View on Github external
test('It should be possible to pass a custom logger function', () => {
    const expectedError = new createError.UnprocessableEntity()
    const logger = jest.fn()

    const handler = middy((event, context, cb) => {
      throw expectedError
    })

    handler
      .use(httpErrorHandler({ logger }))

    // run the handler
    handler({}, {}, (_, response) => {
      expect(logger).toHaveBeenCalledWith(expectedError)
    })
  })
})
github strongloop / loopback-next / packages / rest / src / rest-http-error.ts View on Github external
export function invalidRequestBody(): HttpErrors.HttpError {
    return Object.assign(
      new HttpErrors.UnprocessableEntity(INVALID_REQUEST_BODY_MESSAGE),
      {
        code: 'VALIDATION_FAILED',
      },
    );
  }
github middyjs / middy / src / middlewares / jsonBodyParser.js View on Github external
before: (handler, next) => {
    opts = opts || {}
    const { headers } = handler.event
    if (!headers) {
      return next()
    }
    const contentType = headers['Content-Type'] || headers['content-type']
    if (contentType) {
      const { type } = contentTypeLib.parse(contentType)
      if (type === 'application/json') {
        try {
          handler.event.body = JSON.parse(handler.event.body, opts.reviver)
        } catch (err) {
          throw new createError.UnprocessableEntity('Content type defined as JSON but an invalid JSON was provided')
        }
      }
    }
    next()
  }
})
github fastify / fastify-sensible / lib / httpErrors.js View on Github external
unprocessableEntity: function unprocessableEntity (message) {
    return new createError.UnprocessableEntity(message)
  },