Added 504 error handling in the admin (#18703)

refs https://github.com/TryGhost/Product/issues/4040

Added error handling for 504 errors to improve the message shown to the
user when a 504 occurs
This commit is contained in:
Michael Barrett 2023-10-20 08:53:54 +01:00 committed by GitHub
parent 094ea1d2b0
commit 88e49b4f0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions

View File

@ -178,6 +178,22 @@ export function isEmailError(errorOrStatus, payload) {
}
}
/* Gateway timeout error */
export class GatewayTimeoutError extends AjaxError {
constructor(payload) {
super(payload, 'Server is currently unavailable, please wait a moment then retry.', 504);
}
}
export function isGatewayTimeoutError(errorOrStatus) {
if (isAjaxError(errorOrStatus)) {
return errorOrStatus instanceof GatewayTimeoutError;
} else {
return errorOrStatus === 504;
}
}
/* end: custom error types */
export class AcceptedResponse {
@ -326,6 +342,8 @@ class ajaxService extends AjaxService {
return new EmailError(payload);
} else if (this.isAcceptedResponse(status)) {
return new AcceptedResponse(payload);
} else if (this.isGatewayTimeoutError(status)) {
return new GatewayTimeoutError(payload);
}
let isGhostRequest = GHOST_REQUEST.test(request.url);
@ -404,6 +422,10 @@ class ajaxService extends AjaxService {
return isEmailError(status, payload);
}
isGatewayTimeoutError(status) {
return isGatewayTimeoutError(status);
}
isAcceptedResponse(status) {
return isAcceptedResponse(status);
}

View File

@ -103,7 +103,7 @@ describe('Acceptance: Error Handling', function () {
expect(findAll('.gh-alert').length).to.equal(1);
expect(find('.gh-alert').textContent).to.not.match(/html>/);
expect(find('.gh-alert').textContent).to.match(/Request was rejected due to server error/);
expect(find('.gh-alert').textContent).to.match(/Server is currently unavailable, please wait a moment then retry./);
});
it('handles ember-ajax HTML response', async function () {
@ -118,7 +118,7 @@ describe('Acceptance: Error Handling', function () {
expect(findAll('.gh-alert').length).to.equal(1);
expect(find('.gh-alert').textContent).to.not.match(/html>/);
expect(find('.gh-alert').textContent).to.match(/Request was rejected due to server error/);
expect(find('.gh-alert').textContent).to.match(/Server is currently unavailable, please wait a moment then retry./);
});
});
});