Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
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;
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()
}
}
internalServerError: function internalServerError (message) {
return new createError.InternalServerError(message)
},
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
}
}, {
module.exports = function globalErrorHandler(err, req, reply) {
reply.captureException(err)
reply.send(new httpErrors.InternalServerError())
}
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()
}
}
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 (
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()
}
}