Adding error handling to code example
All checks were successful
ci/woodpecker/push/code-style Pipeline was successful
ci/woodpecker/push/functional-tests Pipeline was successful

This commit is contained in:
Ferdinand Kuhl 2023-08-08 10:48:14 +02:00
parent 5a073ce6b9
commit ad9c9fd678

View file

@ -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();
}
```