如何解决hapijs v17中未返回正确的动臂错误
API控制器:
export const addPaymentCard = async (request: ICustomerAddPaymentCardRequest,h: Responsetoolkit) => {
try {
const { _id: customerId } = request.auth.credentials
const { cardToken } = request.payload
const customerInfo: ICustomer | null = await Customer.findOne({ _id: customerId })
if (!customerInfo) throw Boom.notFound("Customer not found")
if (!customerInfo.stripeId) {
const stripeCustomer = await createStripeCustomer({ email: customerInfo.email,Metadata: { customerId: customerId.toString() } })
await Customer.findOneAndUpdate({ _id: customerInfo._id },{ stripeId: stripeCustomer.id },{ new: true })
customerInfo["stripeId"] = stripeCustomer.id
}
const card = await createStripeSource(customerInfo.stripeId,{ source: cardToken })
return h.response({ statusCode: 200,message: "Success",data: card })
} catch (error) {
logger.error(`${request.method.toupperCase()} ${request.url.pathname},error=${error}`)
throw error
}
}
export const createStripeSource = async (customerId: string,data: Stripe.CustomerSourceCreateParams) => {
try {
const source = await stripe.customers.createSource(customerId,data)
return source
} catch (error) {
logger.error(`create stripe payment methods incurred error=${error}`)
throw error
}
}
预期发送的错误:如无效卡
如何获取Stripe返回的实际错误? 其他方法在任何处理程序中调用时都会返回错误。
节点v12
@ hapi / hapi v20
@ hapi / boom v9
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。