throw new Error('asdasdad')
这样会返回{
error: asdasdad, error_code: 500,
}
如何指定error_code呢?
例如 throw new Error('asdasdad', 400)
自己写一个class继承自Error就可以了。比如:
export default class ApiError extends Error { constructor(msg, code) { super(msg); this.msg = msg; this.code = code; } }
1.4m articles
1.4m replys
5 comments
57.0k users