How to specify different response codes for REST API

Hi @Harri_Sarsa, how do I specify different API response codes (other than 200) in the API Data editor.
In the API Integration page if an api endpoint returns any code different from 200 appgyver just throws an error. I want to be able to specify other response codes and schema like 400 and 500.

My specific use case is connecting to a Bubble backend for authentication. For the login endpoint it can return the following responses:

200 - Login was successful
{
  "status": "string",
  "response": {
    "user_id": "string",
    "token": "string",
    "expires": 0
  }
}

400 - E.g. Wrong password or No user with the email address exists
{
  "statusCode": 0,
  "reason": "string",
  "message": "string",
  "args": {
    "bubble_code": "string"
  }
}

500 - Internal bug at Bubble
{
  "code": "string",
  "message": "string"
}

I know I can merge all the different response schemas into one but appgyver is only able to process 200 responses.

Thanks

Non-2xx responses (specifically, we check if fetch's response.ok is true)should be outputted from the error output of the data flow function with the error code included.

That said, being able to register different expected error codes and their schemas for REST resources would be useful:

https://tracker.appgyver.com/feature-requests/p/allow-rest-api-direct-integration-data-resources-to-register-expected-error-code

However, you should be able to create a “Handle Bubble error code” flow function, that would get the Error output as an input and then output an object with the desired schema, as the status code should be in the rawError object.

Or did I misunderstand you?

Hi @Harri_Sarsa, I’ve been trying to parse the body for non-2xx response without success. I’m thinking there might be some bug in how appgyver handles non-2xx response.

In the example below as you can see I have a 400 response from my backend (Bubble).

.

But when I try both to parse the Error output to get either the code or the message I don’t get any data.

Below is the response when I try to display Create record / Error : code

Below is the response when I try to display Create record / Error : message

I then try to inspect the error response data in the debugger and there too the response from the backend was no where in the data.

I will be very grateful if you can look into this. Note that for 200 response everything works perfectly and i’m able to signup and log users in (will post a tutorial here when this issue is resolved).

Thanks

What happens if you e.g. use Alert to display the whole output object in error route via ENCODE_JSON(outputs["Create record"]) formula? The data should be in outputs["Create record"].error.rawError, if not, it’s a bug.

Hi @Harri_Sarsa, I tried exactly what you suggested by displaying the whole output object via ENCODE_JSON(outputs["Create record"]).

Unfortunately the object was empty.

See a quick screencast below demonstrating this.
I also inspected the rawError from the appgyver debugger and there was nothing in there.

@Harri_Sarsa, just pinging you in case tou haven’t seen my reply here.
Thanks

Yup, there definitely is a bug in handling the error response body – working on a fix right now!

Got a fix done, will push it out next week – sorry for not making the cut before the weekend! :frowning:

No problem @Harri_Sarsa, thanks a lot for looking into this and working on a fix.

If you update your data-related flow functions, this should now work better!

2 Likes

Works now. Thanks @Harri_Sarsa.

1 Like