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; } }
548k questions
547k answers
4 comments
86.3k users