Redirect User based on REST API response
Question
Application Type
Reactive

Hi All,

I am consuming REST API in my application. How Can I navigate the user to the home screen if the HTTP Response.StatusCode = 401?

Thank you for your time.

mvp_badge
MVP

Hi Nannu,


You will need to handle the status code and add it to the output of the rest, see here how.

In this way, after calling the REST API, you can check your status code in an If and navigate to the user in the case it is 401.


Kind Regards,
João

Hi João Marques,

I am using On After Response call back, Inside that I am checking if status code=401 and raising an exception. But instead of raising an exception, I need to navigate the user to the home screen.

Thanks

mvp_badge
MVP

Hi Nannu,


You don't redirect the user in your logic, since it may be running asynchronously (e.g. on a Timer) where there is no user.

The strategy is to have the HTTP code as part of your REST API output and use it in the scope of a screen (where you actually have a user) to redirect it to a user.

Take a look into the articles I and Nordin shared on how to implement this approach.


Kind Regards,
João

mvp_badge
MVP

In addition to João’s answer, take a look at this blogpost from Rui Barbosa to learn all about handling REST errors.

How to Handle HTTP Status Codes When Consuming a REST API in OutSystems

Regards,

Nordin

mvp_badge
MVP

That's a great reading Nordin :)

Hi João Marques & Nordin,

I have read the documentation that you guys provided but I am still confused about how can I navigate the user to the home screen. Also, I have an HTTP status code as part of the REST API output. Basically, I am not sure after getting a 401 Unauthorized when a token is expired how can I  refresh the token and execute the same request again. Can you please provide the sample OML for this? 

Thank you so much for your time, I will look forward to your reply. 

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.