ulys8253
11/08/2022, 3:00 PM"try refresh token" 401 error message to no avail. (The one returned by verifySession when a token has expired)
The SessionInit.errorHandlers.onUnauthorized override method doesn't seem to be called for this error.
We've tried writing a custom verifySession middleware for this only purpose (sad) but can't seem to find a way to overwrite the error message.
Could you point us in the right direction please ? 🥹rp_st
11/08/2022, 3:02 PMgetSession function as shown in this page: https://supertokens.com/docs/session/common-customizations/sessions/session-verification-in-api/get-session
The getSession function throws an error in case of try refresh token or unauthorised which you can catch and send back a custom response to the frontend as you like.rp_st
11/08/2022, 3:02 PMulys8253
11/08/2022, 3:09 PMrp_st
11/08/2022, 3:09 PMulys8253
11/08/2022, 3:11 PMconst verifySession = (options?: VerifySessionOptions) => {
  return async (req: Request, res: Response, next: NextFunction) => {
    try {
      if (options?.sessionRequired === false) {
        (req as any).session = await Session.getSession(req, res, {
          antiCsrfCheck: options?.antiCsrfCheck,
          overrideGlobalClaimValidators: options?.overrideGlobalClaimValidators,
          sessionRequired: false,
        });
      } else {
        (req as any).session = await Session.getSession(req, res, {
          antiCsrfCheck: options?.antiCsrfCheck,
          overrideGlobalClaimValidators: options?.overrideGlobalClaimValidators,
          sessionRequired: true,
        });
      }
      next();
    } catch (err) {
      if (err.type === 'TRY_REFRESH_TOKEN') {
        return next(new Unauthorized(Errors.refresh_token));
      }
      errorHandler()(err, req, res, (err) => next(err));
    }
  };
};rp_st
11/08/2022, 3:12 PMrp_st
11/08/2022, 3:13 PMulys8253
11/08/2022, 3:34 PM