Skip to content

Commit

Permalink
updated the ErrorHandler by adding the handler prop and fixed statement
Browse files Browse the repository at this point in the history
  • Loading branch information
ValeriaMaltseva committed Dec 3, 2024
1 parent 0c1734b commit 84b1acf
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions assets/js/src/core/modules/app/error-handler/error-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,31 @@
* @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL
*/

import { isUndefined } from 'lodash'
import { ErrorModalService } from '@Pimcore/modules/app/error-handler/services/error-modal-service'
import { GeneralError } from '@Pimcore/modules/app/error-handler/index'

interface IErrorContentProvider {
getContent: () => string
}

const trackError = (data: IErrorContentProvider): never => {
type ErrorHandler = (data: string) => void

const isGeneralError = (error: any): boolean => error instanceof GeneralError

const trackError = (data: IErrorContentProvider, handler?: ErrorHandler): never | void => {
const errorContent = data.getContent()

ErrorModalService.showError(errorContent)
if (!isUndefined(handler)) {
handler(errorContent)
} else {
// Default handler
ErrorModalService.showError(errorContent)
}

throw new Error(errorContent)
if (isGeneralError(data)) {
throw new Error(errorContent)
}
}

export default trackError

0 comments on commit 84b1acf

Please sign in to comment.