Skip to content

Commit

Permalink
Report actual server errors in via JS
Browse files Browse the repository at this point in the history
  • Loading branch information
asdil12 committed Jan 27, 2025
1 parent 8e8bddc commit cc263d2
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions assets/javascripts/needleeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,11 +502,22 @@ function saveNeedle(overwrite) {

fetchWithCSRF(form.action, {method: 'POST', body: new FormData(form)})
.then(response => {
if (!response.ok) throw `Server returned ${response.status}: ${response.statusText}`;
return response.json();
return response.json()

Check failure on line 505 in assets/javascripts/needleeditor.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript code (using Node version 20)

Insert `⏎········`
.then(json => {
// Attach the parsed JSON to the response object for further use
return { response, json };

Check failure on line 508 in assets/javascripts/needleeditor.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript code (using Node version 20)

Replace `·response,·json·` with `response,·json`
})
.catch(() => {
// If parsing fails, handle it as a non-JSON response
throw `Server returned ${response.status}: ${response.statusText}`;
});
})
.then(({response, json}) => {
if (!response.ok) `Server returned ${response.status}: ${response.statusText}\n${json.error}`;
if (json.error) throw json.error;
return json;
})
.then(response => {
if (response.error) throw response.error;
if (response.requires_overwrite) {
delete response.requires_overwrite;
const modalElement = document.getElementById('modal-overwrite');
Expand Down

0 comments on commit cc263d2

Please sign in to comment.