Skip to content

Commit

Permalink
improved record update error message (#238)
Browse files Browse the repository at this point in the history
* improved record update error message

* code cleanup

* added Dictionary interface

---------

Co-authored-by: Stefano Ricci <[email protected]>
  • Loading branch information
SteRiccio and SteRiccio authored Aug 16, 2024
1 parent e4c859a commit c7dcffb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/common/Dictionary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface Dictionary<T> {
[key: string]: T
}
2 changes: 2 additions & 0 deletions src/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export type { Dictionary } from './Dictionary'

import { Validation } from '../validation'

export interface ArenaObject<T> {
Expand Down
16 changes: 13 additions & 3 deletions src/error/SystemError.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Dictionary } from '../common'

export class SystemError extends Error {
private _key: string
private _params: { [key: string]: any }
private _params: Dictionary<any>

constructor(key: string, params?: { [key: string]: any }) {
constructor(key: string, params?: Dictionary<any>) {
super(key)

this.name = 'SystemError'
Expand All @@ -20,7 +22,15 @@ export class SystemError extends Error {
return this._key
}

get params(): { [key: string]: string } {
get params(): Dictionary<any> {
return this._params
}

toJSON() {
const { key, params } = this
const { error: nestedError } = params ?? {}
const paramsAdjusted: Dictionary<any> =
nestedError && nestedError instanceof SystemError ? { ...params, error: nestedError?.toJSON() } : params
return { key, params: paramsAdjusted }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ const _throwError = (params: {
const nodeDefName = nodeDef.props.name
const expressionsString = JSON.stringify(expressionsToEvaluate)

throw new SystemError('record.updateSelfAndDependentsDefaultValues.', {
throw new SystemError('record.updateSelfAndDependentsDefaultValues', {
surveyName: survey.props.name,
nodeDefName,
expressionType,
expressionsString,
error: error.toString(),
errorJson: error instanceof SystemError ? error.toJSON() : null,
})
}

Expand Down

0 comments on commit c7dcffb

Please sign in to comment.