自定义Error类
通过继承原生Error类,实现定制的error
class HTTPError extends Error{ constructor(status, statusText, url){ super(`${status} ${statusText}: ${url}`) this.status =status this.statusText = statusText this.url = url } get name(){ return "HTTPError" } } let error = new HTTPError(404, "Not Found", "http://www.baidu.com") error.status // 404 error.statusText // Not Found error.url // http://www.baidu.com

浙公网安备 33010602011771号