'JsonServiceClient not respecting RedirectHttpHandler response

We have a global handler setup for catching a specific type of exception. It is possibly thrown from multiple service endpoints using a base service implementation. We bind the error handlers and try redirect using a RedirectHttpHandler:

ServiceExceptionHandlers.Add(HandledErrorLogging);
...

 private object HandledErrorLogging(IRequest httpreq, object request, Exception ex)
{

    if (ex is NoActiveSubscriptionException)
    {
        return new RedirectHttpHandler
        {
            RelativeUrl = "/account?error=",
            StatusCode = HttpStatusCode.TemporaryRedirect
        };
    }
}

We are using JsonServiceClient to query these endpoints.

The JsonServiceClient is not respecting the RedirectHttpHandler redirect. When we connect jsonclient.responsefilter(r), r.redirectedicted is false:

  let client = new JsonServiceClient(process.env.REACT_APP_API_BASE_URL);
  client.setBearerToken(cookie.load("XSRF-TOKEN"));
  JsonServiceClient.globalResponseFilter = function(e)
  {
    console.log("e.redirect:", e.redirected));
  };
  return client;
}

What is the best way to cause a redirect using the ServiceExceptionHandlers and the JsonServiceClient ?



Solution 1:[1]

RedirectHttpHandler is an IHttpAsyncHandler, it can only be used at the start of the request pipeline in RawHttpHandlers which is used to tell ServiceStack which HttpHandler it should use to handle the request.

ServiceExceptionHandlers is used to override handling of an Exception which you can override to return a different error Response DTO.

If nothing has been written to the Response you can return a redirect response with HttpResult.Redirect().

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mythz