throw new Error('asdasdad')
这样会返回
{
error: asdasdad,
error_code: 500,
}
如何指定error_code呢?
例如 throw new Error('asdasdad', 400)
PHP中文网2017-04-17 16:36:04
Just write a class that inherits from Error. For example:
export default class ApiError extends Error {
constructor(msg, code) {
super(msg);
this.msg = msg;
this.code = code;
}
}