29 lines
518 B
HTML
29 lines
518 B
HTML
<script>
|
|
class HttpError extends Error {
|
|
constructor(response) {
|
|
super(`${response.status} for ${response.url}`);
|
|
this.name = 'HttpError';
|
|
this.response = response;
|
|
}
|
|
}
|
|
|
|
function loadJson(url) {
|
|
return fetch(url)
|
|
.then(response => {
|
|
if (response.status == 200) {
|
|
return response.json();
|
|
} else {
|
|
throw new HttpError(response);
|
|
}
|
|
})
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
.promise-avatar-example {
|
|
border-radius: 50%;
|
|
position: fixed;
|
|
left: 10px;
|
|
top: 10px;
|
|
}
|
|
</style>
|