This package contains an Error provider and formatter around @jaredlunde/curls-addons/Alerts
for
displaying errors in a Drawer-like fashion from the top of the viewport.
yarn add @stellar-apps/errors
import {Errors, ErrorsProvider, ErrorsConsumer} from '@stellar-apps/errors'
function App (props) {
return (
<ErrorsProvider> {/** Stores the errors */}
<ErrorsConsumer>
{({setErrors}) => (
<>
<Errors/> {/** Displays the errors */}
<SomeForm onError={setErrors}/> {/** Sets the errors */}
</>
)}
</ErrorsConsumer>
</ErrorsProvider>
)
}
Provides context for error handling
formatter {func}
- Formats any incoming errors from
setErrors()
in theErrorsConsumer
- Formats any incoming errors from
Provides a function for setting errors (setErrors
) and an array of current errors in the
error context
-
setErrors {func}
- Accepts one argument for setting new errors.
- When the argument is a function, this works exactly like
setState
- When the argument is not a function, any existing errors will be replaced by the errors provided here
- When the argument is a function, this works exactly like
- Errors should stick to a format similar to
{code: 400, message: 'Foo'}
to work with theErrors
component out of the box.
- Accepts one argument for setting new errors.
-
errors {array}
- default
[]
- An array of all current errors in the context
- default
A component for displaying errors in the context in a Drawer-like fashion from the top of the viewport
In addition to the props below, you can provide props for @jaredlunde/curls-addons/Alerts
errorBox {func}
- Renders each individual error
- Has one argument for the following object:
{n, id, code, message}
n {number}
- The index of this error in the
errors
array
- The index of this error in the
id {number|string}
- The ID of the error
code {number}
- Error code if provided in
setErrors
- Error code if provided in
message {string}
- The error message