Skip to content

Commit

Permalink
feat: Improve rendering of error messages when they are JS objects (#…
Browse files Browse the repository at this point in the history
…7548)

* feat: Improve rendering of error messages when they are JS objects

* feat: Improve stringifying the Error when it's logged through BaseError

* fix: Improve renderError to stringify only if object to prevent "double quotes"

---------

Co-authored-by: Begoña Álvarez de la Cruz <[email protected]>
  • Loading branch information
msarcev and begonaalvarezd authored Oct 17, 2023
1 parent cca66a1 commit 607f6d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 5 additions & 2 deletions packages/desktop/components/popups/ErrorLogPopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@
function renderErrorMessage(message: string): string {
if (message !== null && typeof message === 'object') {
return JSON.stringify(message)
try {
return JSON.stringify(message)
} catch {
return message
}
}
return message
}
</script>
Expand Down
11 changes: 9 additions & 2 deletions packages/shared/lib/core/error/classes/base-error.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ export class BaseError extends Error {
}

if (params?.saveToErrorLog) {
const logMessage = String(params?.originalError) ?? message
addError({ ...params, message: logMessage, type: 'BaseError', time: Date.now() })
let logMessage
if (params?.originalError) {
try {
logMessage = JSON.stringify(params.originalError)
} catch {
logMessage = message
}
}
addError({ ...params, message: logMessage ?? message, type: 'BaseError', time: Date.now() })
}

if (params?.showNotification) {
Expand Down

0 comments on commit 607f6d8

Please sign in to comment.