1
0
mirror of https://github.com/flarum/core.git synced 2025-07-16 06:16:23 +02:00

chore: Indicate cross-origin request in generic error message (#3669)

* Indicate cross-origin request in generic error message
* Run javascript format
* Move text to beginning of error message
* Update framework/core/locale/core.yml

Co-authored-by: David Wheatley <hi@davwheat.dev>
This commit is contained in:
Clark Winkelmann
2022-11-20 13:02:41 +01:00
committed by GitHub
parent 5bb0593bad
commit f5c346f1c7
2 changed files with 18 additions and 1 deletions

View File

@ -553,7 +553,11 @@ export default class Application {
break;
default:
content = app.translator.trans('core.lib.error.generic_message');
if (this.requestWasCrossOrigin(error)) {
content = app.translator.trans('core.lib.error.generic_cross_origin_message');
} else {
content = app.translator.trans('core.lib.error.generic_message');
}
}
const isDebug: boolean = app.forum.attribute('debug');
@ -577,6 +581,18 @@ export default class Application {
return Promise.reject(error);
}
/**
* Used to modify the error message shown on the page to help troubleshooting.
* While not certain, a failing cross-origin request likely indicates a missing redirect to Flarum canonical URL.
* Because XHR errors do not expose CORS information, we can only compare the requested URL origin to the page origin.
*
* @param error
* @protected
*/
protected requestWasCrossOrigin(error: RequestError): boolean {
return new URL(error.options.url, document.baseURI).origin !== window.location.origin;
}
protected requestErrorDefaultHandler(e: unknown, isDebug: boolean, formattedErrors: string[]): void {
if (e instanceof RequestError) {
if (isDebug && e.xhr) {