How to use the http-errors.InternalServerError 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 SalakJS / salak / middleware / error.js View on Github external
return async (ctx, next) => {
    try {
      await next()
      if (ctx.response.status === 404 && !ctx.response.body) {
        ctx.throw(404)
      }
    } catch (err) {
      if (!(options.logIgnoreNotFound && err && err.status === 404)) {
        app.logger.error(err)
      }

      if (!err) {
        err = new createError.InternalServerError() // eslint-disable-line
      }

      const code = err.status || 500
      const status = options.status === 'auto' ? code : 200
      ctx.status = status

      let acceptType = options.type || ctx.accepts('json', 'html')

      const output = ctx.app.output || defaultOutput

      switch (acceptType) {
        case 'json':
          let body
          if (err.isJoi) {
            if (err.type === 'RequestValidationError') { // 请求参数出错
              body = output(code, 'request validate fail.', undefined, err.details)
github paulrobertlloyd / indiekit / packages / indieauth / lib / verify-token.js View on Github external
module.exports = (opts, accessToken) => {
  debug('verifyToken opts', opts);

  // Throw error if no publication URL provided
  if (!opts.me) {
    throw new HttpError.InternalServerError('No publication URL provided');
  }

  // Throw error if no access token provided
  if (!accessToken) {
    throw new HttpError.Unauthorized('No access token provided in request');
  }

  // Throw error if access token does not contain a `me` value
  if (!accessToken.me) {
    throw new HttpError.Unauthorized('There was a problem with this access token');
  }

  // Normalize publication and token URLs before comparing
  const accessTokenMe = normalizeUrl(accessToken.me);
  const publicationMe = normalizeUrl(opts.me);
  const isAuthenticated = accessTokenMe === publicationMe;
github middyjs / middy / src / middlewares / validator.js View on Github external
after (handler, next) {
      if (!outputSchema || (!handler.response && handler.error)) {
        return next()
      }

      const valid = validateOutput(handler.response)

      if (!valid) {
        const error = new createError.InternalServerError('Response object failed validation')
        error.details = validateOutput.errors
        error.response = handler.response
        throw error
      }

      return next()
    }
  }
github fastify / fastify-sensible / lib / httpErrors.js View on Github external
internalServerError: function internalServerError (message) {
    return new createError.InternalServerError(message)
  },
github mcollina / fastify-gql / index.js View on Github external
if (cached && cached.jit !== null) {
      const res = await cached.jit.query(root, context, variables || {})
      return res
    }

    const execution = await execute(
      schema,
      document,
      root,
      context,
      variables,
      operationName
    )
    if (execution.errors) {
      const err = new InternalServerError()
      err.errors = execution.errors
      throw err
    }

    return execution
  }
}, {
github lifechurch / melos / elaphros / plugins / main / global-error-handler.js View on Github external
module.exports = function globalErrorHandler(err, req, reply) {
  reply.captureException(err)
  reply.send(new httpErrors.InternalServerError())
}
github cablelabs / lpwanserver / app / models / IUser.js View on Github external
Object.assign(userUpdate, {
        email: user.lastVerifiedEmail,
        lastVerifiedEmail: '',
        emailVerified: true
      })
    }
    try {
      await this.update(userUpdate)
      await deleteEmailVerification(uuid)
    }
    catch (err) {
      logger.error('Update for EmailVerify failed. UUID = ' + uuid +
                                           ', type = ' + type +
                                           ', source = ' + source +
                                          ': ', err)
      throw httpError.InternalServerError()
    }
  }
github commonshost / playdoh / middleware.js View on Github external
return next(new MethodNotAllowed())
    }

    if (dnsMessage.length === 0 || dnsMessage[0].length < 2) {
      return next(new BadRequest())
    }
    const requestDnsId = dnsMessage[0].readUInt16BE(0)
    await promisify(randomFill)(dnsMessage[0], 0, 2)
    const nonceDnsId = dnsMessage[0].readUInt16BE(0)

    let socket
    try {
      socket = createSocket(protocol)
      socket.bind({ address: localAddress, exclusive: true })
    } catch (error) {
      return next(new InternalServerError())
    }

    socket.once('error', () => next(new BadGateway()))

    socket.once('listening', () => {
      const timer = setTimeout(() => {
        socket.close()
        next(new GatewayTimeout())
      }, timeout)
      socket.once('close', () => clearTimeout(timer))
      socket.send(dnsMessage, resolverPort, resolverAddress)
      dnsMessage.length = 0
    })

    socket.on('message', (message, { port, address }) => {
      if (
github cablelabs / lpwanserver / rest / models / dao / production / users.js View on Github external
Object.assign(userUpdate, {
      email: user.lastVerifiedEmail,
      lastVerifiedEmail: '',
      emailVerified: true
    })
  }
  try {
    await updateUser(userUpdate)
    await deleteEmailVerification(uuid)
  }
  catch (err) {
    appLogger.log('Update for EmailVerify failed. UUID = ' + uuid +
                                         ', type = ' + type +
                                         ', source = ' + source +
                                        ': ' + err)
    throw httpError.InternalServerError()
  }
}