Client - display info and errors on workout edition

This commit is contained in:
Sam
2021-09-29 16:34:48 +02:00
parent 6bfcb24133
commit 997469d959
10 changed files with 182 additions and 28 deletions

View File

@ -17,8 +17,7 @@ export const getApiUrl = (): string => {
// TODO: update api error messages to remove these workarounds
const removeLastEndOfLine = (text: string): string => text.replace(/\n$/gm, '')
const removeLastDot = (text: string): string => text.replace(/\.$/gm, '')
const removeErrorDot = (text: string): string =>
text.replace(/^Error\./gm, 'Error,')
const replaceInternalDots = (text: string): string => text.replace(/\./gm, ',')
export const handleError = (
context:
@ -33,14 +32,16 @@ export const handleError = (
let errorMessages = !error
? msg
: error.response
? error.response.data.message
? error.response.status === 413
? 'File size is greater than the allowed size'
: error.response.data.message
? error.response.data.message
: msg
: error.message
? error.message
: msg
errorMessages = removeLastEndOfLine(errorMessages)
errorMessages = removeErrorDot(errorMessages)
errorMessages = replaceInternalDots(errorMessages)
context.commit(
ROOT_STORE.MUTATIONS.SET_ERROR_MESSAGES,
errorMessages.includes('\n')