diff --git a/README.md b/README.md index 0e01ccb..0c0294d 100644 --- a/README.md +++ b/README.md @@ -34,11 +34,14 @@ Your JavaScript could look like that: ```javascript async function translate(idPatterns) { - return fetch(document.location, {headers: { + const response = await fetch(document.location, {headers: { 'X-Translation-Request': idPatterns, 'Accept-Language': document.documentElement.lang - }}) - .then(response => response.json()); + }}); + if (! response.ok) { + return Promise.reject('Unexpected server response'); + } + return await response.json(); } ```