Skip to main content

Errors

Errors thrown by the Dashboard SDK. MoBro catches errors thrown by widgets and shows them on the dashboard, see In-depth: Error Handling.

MetricDoesNotExistError

Thrown by useMetricField and useMemoizedMetricField if the selected metric doesn't exist, e.g. because the plugin providing it was uninstalled.

Extends WidgetErrorWithPayload with the following payload:

PropertyTypeDescription
metricIdstringThe id of the metric.
configValueMetricConfigThe configuration of the metric field.

isMissingMetricError

Returns whether an error, or an error name, is a MetricDoesNotExistError.

function isMissingMetricError(error: string | Error): boolean

WidgetErrorWithPayload

An Error carrying additional data. MoBro passes the payload of errors thrown by widgets along with the error message.

class WidgetErrorWithPayload<T> extends Error {
constructor(message: string, payload: T)

getPayload(): T
}

Example

src/widgets/example/Example.tsx
import React from 'react'
import {WidgetErrorWithPayload, useNumberField} from '@modbros/dashboard-sdk'

export default function Example() {
const max = useNumberField({field: 'max', defaultValue: 100})

if (max <= 0) {
throw new WidgetErrorWithPayload('The maximum must be greater than 0.', {max})
}

return <span>Max: {max}</span>
}