Les Partages de Memiks
Tag cloud
Picture wall
Daily
RSS Feed
  • RSS Feed
  • Daily Feed
  • Weekly Feed
  • Monthly Feed
Filters

Links per page

  • 20 links
  • 50 links
  • 100 links

Filters

Untagged links
Handling Failed HTTP Responses With fetch() http://tjvantoll.com/2015/09/13/fetch-and-errors/
Tue Sep 15 22:16:28 2015 archive.org
QRCode
thumbnail

J'adore utiliser ce genre d'artéfact.

j'aime codé en javascript pour cela car c'est "simple" d'étendre le fonctionnement existant.

function handleErrors(response) {
if (!response.ok) {
return Promise.reject(new Error(response.statusText));
}
return Promise.resolve(response);
}

fetch("http://httpstat.us/500")
.then(handleErrors)
.then(function(response) {
console.log("ok");
}).catch(function(error) {
console.log(error);
});

ES6

function handleErrors(response) {
if (!response.ok) {
return Promise.reject(new Error(response.statusText));
}
return Promise.resolve(response);
}
fetch("http://httpstat.us/500")
.then(handleErrors)
.then(response => console.log("ok") )
.catch(error => console.log(error) );

ES6 jquery javascript
4756 links, including 1670 private
Shaarli - The personal, minimalist, super-fast, database free, bookmarking service by the Shaarli community - Theme by kalvn