Seeking Opinions on Using Effect with TRPC/ORPC for Error Handling

Hi, I'd like to love about some opinions on the usage with effect and TRPC / ORPC. I currently have a solution that works but somehow feels like an antipattern?

Im running my mutations as an exit and transform failures to an either, which is then returned over the wire, so I can match known errors on the frontent:
 const handleTokenSubmission = ({ code }: { code: string }) => {
    mutate(
      { token: code },
      {
        onSuccess: Either.match({
          onLeft: (error) => {
            switch (error._tag) {
              case "AuthenticationProcessExpiredError": {
                return  toast.error(t('errors.tokenExpired.title'), {
                  action: {
                    label: t('errors.tokenExpired.action'),
                    onClick: () => setRegistrationState(null),
                  },
                })
              }
              case "InvalidAuthenticationProcessTokenError": {
                return  toast.error(t('errors.tokenInvalid.title'), {
                  action: {
                    label: t('errors.tokenInvalid.action'),
                    onClick: () => setRegistrationState(null),
                  },
                })
              }
              default: {
                return  toast.error(t('errors.internalError.title'), {
                  action: {
                    label: t('errors.internalError.action'),
                    onClick: () => setRegistrationState(null),
                  },
                })
              }
            }
          },
          onRight: ({nextStage}) => {
            if (nextStage === 'TWO_FACTOR_REQUIRED') {
              navigate(href('/login/2fa'));
            } else {
              navigate(redirectTo ?? '/');
            }
          }
        }),
      },
    );
  };


Whats your opinions on this? That way the "error" channel is reserved for defects.
Was this page helpful?