Node.js @hapi/动臂未返回正确错误,取而代之的是“;500:内部服务器错误“;
@hapi/boom未返回代码中抛出的正确错误。 以下是代码示例: 控制器Node.js @hapi/动臂未返回正确错误,取而代之的是“;500:内部服务器错误“;,node.js,error-handling,google-authentication,hapi,google-auth-library-nodejs,Node.js,Error Handling,Google Authentication,Hapi,Google Auth Library Nodejs,@hapi/boom未返回代码中抛出的正确错误。 以下是代码示例: 控制器 async (request: IRequest, h: IResponse) => { .... // some logic const userInfo = await verify(email, authToken) if (!userInfo) throw Boom.unauthorized(`Unable to fetch user information`) .... some logic
async (request: IRequest, h: IResponse) => {
.... // some logic
const userInfo = await verify(email, authToken)
if (!userInfo) throw Boom.unauthorized(`Unable to fetch user information`)
.... some logic
return h.response({ statusCode: 200, message: "Success", data })
} catch (error) {
throw error
}
验证.ts
export async function verify(userEmail: string, token: string) {
try {
const ticket = await client.verifyIdToken({
idToken: token,
audience: clientId
})
const payload = ticket.getPayload()
if (!payload) throw Boom.unauthorized("Google authentication failed")
const { sub: userId, name, email, aud, picture: profilePhoto } = payload
if (!aud || aud !== clientId) throw Boom.unauthorized(`Invalid token for ${config.get("appName")}`)
if (!email || email !== userEmail) throw Boom.unauthorized(`Invalid token for email ${userEmail}`)
return { userId, name, profilePhoto, email }
} catch (error) {
logger.error(error)
throw error
}
}
现在,如果出现错误,它应该返回未经授权的,但它总是返回内部服务器错误
有什么方法可以返回带有信息的实际错误
堆栈:
@hapi/hapi:20.0.3
@hapi/boom:9.1.1Error 500字面意思是服务器中有错误。