11.3.4.2. 返回状态代码
您可以通过在返回对象中添加 statusCode 属性来设置 return 到调用者的状态代码:
状态代码示例
function handle(context, customer) {
// process customer
if (customer.restricted) {
return { statusCode: 451 }
}
}
也可以为函数创建和丢弃的错误设置状态代码:
错误状态代码示例
function handle(context, customer) {
// process customer
if (customer.restricted) {
const err = new Error(‘Unavailable for legal reasons’);
err.statusCode = 451;
throw err;
}
}