Skip to content

Commit ae72c05

Browse files
committed
Improve error reporting on PHP errors
1 parent 9b6d08f commit ae72c05

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

view/base/templates/script/ajax-queue.phtml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,18 @@ if ($interval < 10) {
100100
headers: this.getPostHeaders(),
101101
body: JSON.stringify(this.buildBody(requests))
102102
})
103-
.then(response => {
103+
.then(async response => {
104+
const body = await response.text();
104105
if (response.ok) {
105-
return response.text()
106+
return body;
106107
}
107108

108109
LokiComponentsLogger.error('Fetch error', response);
109-
throw new Error(response.statusText);
110+
111+
const error = new Error(response.statusText);
112+
error.status = response.status;
113+
error.body = body;
114+
throw error;
110115
})
111116
.then(html => {
112117
try {
@@ -122,7 +127,12 @@ if ($interval < 10) {
122127
this.afterPostSuccess(incomingRequests);
123128
})
124129
.catch(error => {
125-
Alpine.store('Message').addErrorMessage(error);
130+
let errorMessage = error.name;
131+
if (error.body) {
132+
errorMessage = error.body.split(/\r?\n/)[0];
133+
}
134+
135+
Alpine.store('Message').addErrorMessage(errorMessage);
126136
})
127137
.finally(() => {
128138
this.afterPostFinally(incomingRequests);

0 commit comments

Comments
 (0)