diff --git a/src/locales/en.json5 b/src/locales/en.json5 index e2d7f0863..d8ef4fff7 100644 --- a/src/locales/en.json5 +++ b/src/locales/en.json5 @@ -441,8 +441,7 @@ "mixin": { "request": { "alert": { - "fileSize": "The file “{name}” that you are trying to upload is larger than the 100 MB limit.", - "entityTooLarge": "The data that you are trying to upload is too large.", + "fileSize": "The file “{name}” that you are trying to upload is larger than the 100 MB limit." } } }, @@ -475,6 +474,11 @@ "noResponse": "Something went wrong: there was no response to your request.", // {status} is an HTTP status code, for example, 404. "errorNotProblem": "Something went wrong: error code {status}.", + "error": { + // @transifexKey mixin.request.alert.entityTooLarge + "413": "The data that you are trying to upload is too large.", + "504": "Your request took too long, and Central stopped waiting for it." + }, "problem": { // A "resource" is a generic term for something in Central, for example, // a Project, a Web User, or a Form. diff --git a/src/util/request.js b/src/util/request.js index bb4c19053..eb0b61ad0 100644 --- a/src/util/request.js +++ b/src/util/request.js @@ -231,9 +231,10 @@ export const requestAlertMessage = (i18n, axiosError, problemToAlert = undefined const { response } = axiosError; if (response == null) return i18n.t('util.request.noResponse'); if (!(axiosError.config.url.startsWith('/v1/') && isProblem(response.data))) { - if (response.status === 413) - return i18n.t('mixin.request.alert.entityTooLarge'); - return i18n.t('util.request.errorNotProblem', response); + const key = `util.request.error.${response.status}`; + return i18n.te(key) + ? i18n.t(key) + : i18n.t('util.request.errorNotProblem', response); } const problem = response.data; diff --git a/test/unit/request.spec.js b/test/unit/request.spec.js index 433f30ca2..e196cb3f3 100644 --- a/test/unit/request.spec.js +++ b/test/unit/request.spec.js @@ -631,13 +631,24 @@ describe('util/request', () => { message.should.equal('Something went wrong: error code 500.'); }); - it('returns a message about 413 error response that is not a Problem', () => { - const message = requestAlertMessage(i18n, mockAxiosError({ - status: 413, - data: '