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; } }
2.1m questions
2.1m answers
60 comments
57.0k users