For a larger app, it makes sense to make this function more general (and therefore more versatile), by allowing some arbitrary function to be executed in the case of an error (just like you're doing in the case of a successful response). There's two ways you can do this:
https://github.com/fac-13/jeth/blob/55aa475205ea69a649432a9c9cfd0b7e1854d083/public/dom.js#L3
This is fine, but you've hardcoded specific error handling actions inside this function:
https://github.com/fac-13/jeth/blob/55aa475205ea69a649432a9c9cfd0b7e1854d083/public/dom.js#L9-L23
For a larger app, it makes sense to make this function more general (and therefore more versatile), by allowing some arbitrary function to be executed in the case of an error (just like you're doing in the case of a successful response). There's two ways you can do this:
Accept a second callback argument in
fetch
.Use the error-first callback pattern: