summaryrefslogtreecommitdiff
path: root/doc/development/fe_guide/style/javascript.md
diff options
context:
space:
mode:
Diffstat (limited to 'doc/development/fe_guide/style/javascript.md')
-rw-r--r--doc/development/fe_guide/style/javascript.md21
1 files changed, 12 insertions, 9 deletions
diff --git a/doc/development/fe_guide/style/javascript.md b/doc/development/fe_guide/style/javascript.md
index b35ffdd8669..987543642f0 100644
--- a/doc/development/fe_guide/style/javascript.md
+++ b/doc/development/fe_guide/style/javascript.md
@@ -2,7 +2,6 @@
stage: none
group: unassigned
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments
-disqus_identifier: 'https://docs.gitlab.com/ee/development/fe_guide/style_guide_js.html'
---
# JavaScript style guide
@@ -332,19 +331,23 @@ Only export the constants as a collection (array, or object) when there is a nee
## Error handling
-When catching a server-side error you should use the error message
+When catching a server-side error, you should use the error message
utility function contained in `app/assets/javascripts/lib/utils/error_message.js`.
-This utility parses the received error message and checks for a prefix that indicates
-whether the message is meant to be user-facing or not. The utility returns
-an object with the message, and a boolean indicating whether the message is meant to be user-facing or not. Please make sure that the Backend is aware of the utils usage and is adding the prefix
-to the error message accordingly.
+This utility accepts two parameters: the error object received from the server response and a
+default error message. The utility examines the message in the error object for a prefix that
+indicates whether the message is meant to be user-facing or not. If the message is intended
+to be user-facing, the utility returns it as is. Otherwise, it returns the default error
+message passed as a parameter.
```javascript
import { parseErrorMessage } from '~/lib/utils/error_message';
onError(error) {
- const { message, userFacing } = parseErrorMessage(error);
-
- const errorMessage = userFacing ? message : genericErrorText;
+ const errorMessage = parseErrorMessage(error, genericErrorText);
}
```
+
+To benefit from this parsing mechanism, the utility user should ensure that the server-side
+code is aware of this utility's usage and prefixes the error messages where appropriate
+before sending them back to the user. See
+[Error handling for API](../../api_styleguide.md#error-handling) for more information.