How to use the http-errors.BadGateway 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 fastify / fastify-sensible / lib / httpErrors.js View on Github external
badGateway: function badGateway (message) {
    return new createError.BadGateway(message)
  },
github commonshost / playdoh / middleware.js View on Github external
socket.on('message', (message, { port, address }) => {
      if (
        message.length < 2 ||
        message.readUInt16BE(0) !== nonceDnsId ||
        address !== resolverAddress ||
        port !== resolverPort
      ) {
        return
      }
      message.writeUInt16BE(requestDnsId, 0)
      if (request.method === HTTP2_METHOD_GET) {
        let answers
        try {
          ({ answers } = decode(message))
        } catch (error) {
          return next(new BadGateway())
        }
        const ttl = answers.reduce(smallestTtl, Infinity)
        if (Number.isFinite(ttl)) {
          response.setHeader(HTTP2_HEADER_CACHE_CONTROL, `max-age=${ttl}`)
        }
      }
      response.setHeader(HTTP2_HEADER_CONTENT_LENGTH, message.length)
      response.setHeader(HTTP2_HEADER_CONTENT_TYPE, dohMediaType)
      response.end(message)
      socket.close()
    })
  }