The sharedFacetDriver defines an error case, which calls an onError handler which should be set by either a specific useSharedFacet() instance or one of the new <SharedFacetsErrorBoundary /> instances which should catch any errors in any facet within it's scope and handle the error with the error handler you pass to it
And the the end user can re-define what the error type should look like using the declaration merging typescript feature, we went with this implementation to make sure the end user gets typesafety in their error handling which they can re-define to suit their needs.
// This is how we've opted to allow users to extend the error type to their usecases, they re-declare the
// interface for SharedErrorFacet with whatever extensions they want
// the original type just has facetName as mandatory and we add ontop of that facetError as mandatory in this case
declare module '@mojang/shared-facet' {
export interface SharedFacetError {
facetError: string
}
}
The end result of the type in the user's codebase would look something like this.
This PR adds a way to define errors for
SharedFacet
s in theSharedFacetDriver
using the onError callback like soThe sharedFacetDriver defines an error case, which calls an onError handler which should be set by either a specific
useSharedFacet()
instance or one of the new<SharedFacetsErrorBoundary />
instances which should catch any errors in any facet within it's scope and handle the error with the error handler you pass to itExample usage of a local facet error handler
Example of the usage of a
<SharedFacetsErrorBoundary />
The error you get passed to your callback from the sharedFacetDriver is of type
SharedFacetError
and it's basic type looks like soAnd the the end user can re-define what the error type should look like using the declaration merging typescript feature, we went with this implementation to make sure the end user gets typesafety in their error handling which they can re-define to suit their needs.
The end result of the type in the user's codebase would look something like this.