Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #36660
| Newsgroups | comp.lang.javascript |
|---|---|
| From | Andrew Poulos <ap_prog@hotmail.com> |
| Subject | throw error in fetch with response text |
| Date | 2019-05-29 10:23 +1000 |
| Message-ID | <LMqdnXFmEY6FTHDBnZ2dnUU7-QXNnZ2d@westnet.com.au> (permalink) |
With this
fetch(url)
.then (function(response) {
let contentType = response.headers.get("content-type");
if (contentType && contentType.indexOf("text/html") !== -1) {
throw response.text();
} else {
return response.blob();
}
})
.then (blob => window.URL.createObjectURL(blob))
.then (ourl => {
// do stuff
})
.catch(function(error) {
window.alert(err);
});
when there's an error the server returns some text describing the error
(instead of a blob when there's no error).
The alert though only displays [object Promise]. How do I get the
'PromiseValue' text into the alert?
Andrew Poulos
Back to comp.lang.javascript | Previous | Next — Next in thread | Find similar | Unroll thread
throw error in fetch with response text Andrew Poulos <ap_prog@hotmail.com> - 2019-05-29 10:23 +1000 Re: throw error in fetch with response text Andrew Poulos <ap_prog@hotmail.com> - 2019-05-29 10:33 +1000
csiph-web