{@code StructureException} can be thrown for different causes that involve Structure plugin. It usually means that theoperation that is traced back to the user's action, cannot be performed and should be reported as error.
Each exception is associated with a specific value from enumeration {@link StructureError}. Exception may also carry additional message description and information about affected structure, view or issue. The general method {@link #getMessage()}, returns all information included with the exception, except for the stack trace and cause.
To display an error on the user interface: use {@link #getLocalizedMessage()} or {@link #getLocalizedMessage(com.atlassian.crowd.embedded.api.User)}to get a human-friendly error in the user's locale. However, in many cases the error message will not be localized and the result of {@code getLocalizedMessage()} will contain the problem description as a developer had put it in English.(It might not be human-friendly even for English audience!)
So for the best result, you should check {@link #isLocalized()}method and if exception is not localized, use some wrapper text to display the error to the user in a good way:
Java code: try { ... } catch (StructureException e) { if (e.isLocalized()) { setDisplayedError(e.getLocalizedMessage()); } else { setDisplayedError(getText("my.errors.structure-error", e.getLocalizedMessage())); } } I18N Properties: my.errors.structure-error=Some problem happened with structure, sorry! ({0})
An instance of {@code StructureException} may be created by using one of the available constructors, butit might be more convenient to start from {@link StructureError} and use chained builder commands, ending withmessage specification:
throw StructureError.GENERIC_ERROR.withMessage("cannot foo bar"); ... throw StructureError.INVALID_JQL.causedBy(caughtException).forStructure(id).withoutMessage(); ... throw StructureError.VIEW_EDIT_DENIED.forView(id).withLocalizedMessage("error.view.edit.denied", id, name);@see StructureError
|
|
|
|
|
|