GUACAMOLE-926: Always use translation system for errors.

This commit is contained in:
James Muehlner
2023-04-06 00:39:19 +00:00
parent d657d2b90a
commit 8aaa636705
6 changed files with 113 additions and 26 deletions

View File

@@ -155,6 +155,10 @@ angular.module('import').directive('connectionImportErrors', [
if (!patchFailure || !parseResult)
return;
// All promises from all translation requests. The scope will not be
// updated until all translations are ready.
const translationPromises = [];
// Set up the list of connection errors based on the existing parse
// result, with error messages fetched from the patch failure
$scope.connectionErrors = parseResult.patches.map(
@@ -166,10 +170,24 @@ angular.module('import').directive('connectionImportErrors', [
// Set the error from the PATCH request, if there is one
const error = _.get(patchFailure, ['patches', index, 'error']);
if (error)
connectionError.errors = new DisplayErrorList([error]);
// Fetch the translation and update it when it's ready
translationPromises.push($translate(
error.key, error.variables)
.then(translatedError =>
connectionError.errors.getArray().push(translatedError)
));
return connectionError;
});
// Once all the translations have been completed, update the
// connectionErrors all in one go, to ensure no excessive reloading
$q.all(translationPromises).then(() => {
$scope.connectionErrors = connectionErrors;
});
});
// If a new parse result with errors is seen, update the display list

View File

@@ -61,6 +61,13 @@ angular.module('import').factory('ParseError', [function defineParseError() {
*/
this.variables = template.variables;
// If no translation key is available, fall back to the untranslated
// key, passing the raw message directly through the translation system
if (!this.key) {
this.key = 'APP.TEXT_UNTRANSLATED';
this.variables = { MESSAGE: this.message };
}
};
return ParseError;

View File

@@ -68,7 +68,7 @@ angular.module('rest').factory('DirectoryPatchOutcome', [
* The error message associated with the failure, if the patch failed to
* apply.
*
* @type {String}
* @type {TranslatableMessage}
*/
this.error = template.error;