Issue with Forge API's invokeRemote not Catching Non-200 Error Codes in React Application

Hi everyone!

I’m having an issue using the Forge API, specifically with the Invoke Remote API

I’m using invokeRemote to make calls to my application’s services from the front end with React. The problem is that when the service responds with an error code other than 500, such as a 408 error code, these are not being caught by the catch block that handles the service.

Here’s an example of how I’m using the API:

return await invokeRemote({
    method: "GET",
    headers: {
        "Accept": "application/json",
        "Content-type": "application/json"
    path: `customPath`,
}).then((result) => {
    return result;
}).catch((error) => {
    return error;

I would expect that when the service I’m calling returns a success code (200-299), it would be caught by the then block, and the catch block would catch any other code.

Reviewing the documentation, it states:

Therefore, I would expect the behavior to be that any non-200 code should be caught in the catch block.

I’m unsure if I’m misunderstanding something or have something misconfigured. If anyone has more information, it would be very helpful.

Thanks in advance and best regards!

1 Like