Sample network error script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let responseObj = new Response('http://example.com/', { status: 200, statusText: 'All good' }); | |
//Network errors | |
class NetworkError extends Error { | |
constructor(msg, response) { | |
super(msg); | |
this.name = 'NetworkError'; | |
this.response = response; | |
this.status = response.status; | |
this.text = response.statusText; | |
} | |
} | |
let ne = new NetworkError('some message', responseObj); | |
console.log({ ne }); | |
throw ne; | |
/* | |
Alternate non-class syntax version | |
const NetworkError2 = function (msg, response) { | |
this.message = msg; | |
this.response = response; | |
this.status = response.status; | |
this.text = response.statusText; | |
}; | |
Object.setPrototypeOf(NetworkError2.prototype, Error.prototype); | |
//or NetworkError2.prototype.__proto__ = Error.prototype | |
let ne2 = new NetworkError2('some message', responseObj); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment