handle forbidden and not found errors on text page
This commit is contained in:
parent
a71cd641dc
commit
b5040fff14
1 changed files with 18 additions and 2 deletions
|
|
@ -4,8 +4,24 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
const textId = window.location.pathname.split('/').pop();
|
const textId = window.location.pathname.split('/').pop();
|
||||||
|
|
||||||
fetch('/api/texts/' + textId, { credentials: 'same-origin' })
|
fetch('/api/texts/' + textId, { credentials: 'same-origin' })
|
||||||
.then(res => res.json())
|
.then(function (res) {
|
||||||
.then(text => {
|
if (!res.ok) {
|
||||||
|
if (res.status === 403) {
|
||||||
|
const message = document.createElement('p');
|
||||||
|
message.textContent =
|
||||||
|
"You don't have permission to view this text";
|
||||||
|
document.getElementById('text-detail').appendChild(message);
|
||||||
|
} else if (res.status === 404) {
|
||||||
|
const message = document.createElement('p');
|
||||||
|
message.textContent = 'Text not found';
|
||||||
|
document.getElementById('text-detail').appendChild(message);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return res.json();
|
||||||
|
})
|
||||||
|
.then(function (text) {
|
||||||
|
if (!text) return;
|
||||||
const h1 = document.createElement('h1');
|
const h1 = document.createElement('h1');
|
||||||
h1.textContent = text.name;
|
h1.textContent = text.name;
|
||||||
document.getElementById('text-detail').appendChild(h1);
|
document.getElementById('text-detail').appendChild(h1);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue