-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ADDON-57381 hide implementation details from user-facing error …
…messages (#987) https://splunk.atlassian.net/browse/ADDON-57381 - [x] parse BE errors with omitting stack traces - [x] move error message to the center - [x] get rid of bindings on error codes on FE side. Just show BE error - [x] remove AxiosError - it is too technical to the user --------- Co-authored-by: Viktor Tsvetkov <142901247+vtsvetkov-splunk@users.noreply.github.com>
- Loading branch information
1 parent
0a9103e
commit 5467ed9
Showing
11 changed files
with
145 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
ui/src/components/ErrorBoundary/stories/__images__/ErrorBoundary-base-chromium.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import * as __ from 'lodash'; | ||
import { _ } from '@splunk/ui-utils/i18n'; | ||
import messageDict from '../constants/messageDict'; | ||
|
||
/** | ||
* @param code a int value. | ||
* @param msg arguments to format the message. | ||
*/ | ||
export const getFormattedMessage = (code: number, msg?: (string | number | boolean)[]): string => { | ||
let template = messageDict[code] || messageDict.unknown; | ||
template = _(template); | ||
return __.template(template, { | ||
escape: /\{\{(.+?)\}\}/g, | ||
})({ | ||
args: msg, | ||
}); | ||
}; | ||
|
||
const tryParseByteString = (text: string) => { | ||
try { | ||
if (text.startsWith(`b'`) || text.startsWith(`b"`)) { | ||
// bytestring starts from b and Quotation mark (b') and ends with Quotation mark(') | ||
const parsedString = JSON.parse(text.slice(2, -1)); | ||
return String(parsedString.messages[0].text); | ||
} | ||
return text; | ||
} catch { | ||
return text; | ||
} | ||
}; | ||
|
||
export const tryTrimErrorMessage = (msg: string) => { | ||
try { | ||
const regex = | ||
/.+"REST Error \[[\d]+\]:\s+.+\s+--\s+([\s\S]*)"\.\s*See splunkd\.log(\/python.log)? for more details\./; | ||
const matches = regex.exec(msg); | ||
if (matches && matches[1]) { | ||
try { | ||
const innerMsgJSON = JSON.parse(matches[1]); | ||
return String(innerMsgJSON.messages[0].text); | ||
} catch (error) { | ||
return tryParseByteString(matches[1]); | ||
} | ||
} | ||
} catch (e) { | ||
return msg; | ||
} | ||
|
||
return msg; | ||
}; | ||
|
||
export const parseErrorMsg = (err?: { | ||
response?: { data?: { messages?: { text?: string }[] } }; | ||
}) => { | ||
try { | ||
const msg = err?.response?.data?.messages?.[0]?.text; | ||
if (!msg) { | ||
return messageDict.unknown; | ||
} | ||
return tryTrimErrorMessage(msg); | ||
} catch (e) { | ||
return _('Error in processing the request'); | ||
} | ||
}; |