diff options
Diffstat (limited to 'app/assets/javascripts/notes/utils.js')
-rw-r--r-- | app/assets/javascripts/notes/utils.js | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/app/assets/javascripts/notes/utils.js b/app/assets/javascripts/notes/utils.js index ed1c80e7a6e..c5859a89182 100644 --- a/app/assets/javascripts/notes/utils.js +++ b/app/assets/javascripts/notes/utils.js @@ -2,6 +2,9 @@ import { marked } from 'marked'; import markedBidi from 'marked-bidi'; import { sanitize } from '~/lib/dompurify'; import { markdownConfig } from '~/lib/utils/text_utility'; +import { HTTP_STATUS_UNPROCESSABLE_ENTITY } from '~/lib/utils/http_status'; +import { sprintf } from '~/locale'; +import { COMMENT_FORM } from './i18n'; /** * Tracks snowplow event when User toggles timeline view @@ -19,3 +22,17 @@ marked.use(markedBidi()); export const renderMarkdown = (rawMarkdown) => { return sanitize(marked(rawMarkdown), markdownConfig); }; + +export const getErrorMessages = (data, status) => { + const errors = data?.errors; + + if (errors && status === HTTP_STATUS_UNPROCESSABLE_ENTITY) { + if (errors.commands_only?.length) { + return errors.commands_only; + } + + return [sprintf(COMMENT_FORM.error, { reason: errors.toLowerCase() }, false)]; + } + + return [COMMENT_FORM.GENERIC_UNSUBMITTABLE_NETWORK]; +}; |