Skip to content

How to create a custom boundary? How to catch custom errors? #193

@OnkelTem

Description

@OnkelTem

Currently there is only one boundary - NotFoundBoundary which catches only NotFoundError errors. In my app I also need to prevent access to specific pages and for that I would like to create a custom error - e.g.AccessDeniedError and corresponding boundary as well. But I'm not sure how to do it. The original NotFoundBoundary uses NaviContext which is not exported.

import { NaviContext } from './NaviContext'

export const NotFoundBoundary: React.SFC<NotFoundBoundaryProps> = function ErrorBoundary(props: NotFoundBoundaryProps) {
  return (
    <NaviContext.Consumer>
      {context => <InnerNotFoundBoundary context={context} {...props} />}
    </NaviContext.Consumer>
  )
}

So how can one add new error types and effectively catch them?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions