Expected JSON Response for Error Handling

What's this about in laymen's terms: We rely on Bubble's own infrastructure and internal functions which turns your Supabase Data into Bubble objects ready to be used. We're doing so by mimicking what the API connector does for us and a bit more.

Some background: When you initialize an API call, Bubble sets up a lot of things in the background. It basically creates a schema of what kind of data it expects (and some other error handling on top of it, but we don't have to worry about that).

So when you initialize a call, Bubble will checks the response and tries to find the values to determine how he can parse the response later. By doing so it can also setup the related points to know when certain fields are empty how to parse them or more like how to essentially skip them.

Let's add the same functionality to the Plugin. All we need to do is head over to the API connector where we've initially setup the Data, and click on Manually enter API response.

This is what you should see (obviously the JSON will be different). Copy the contect to the clipboard and enter it in the related Supabase Data element's "Expected JSON Response" field.

As you can see all of the fields have some kind of value. These values should not be sensitive data, although the code we run is protected.

These values won't be used, we just need to determine what kind of default empty value we need to add. Most importantly numbers and arrays. Let's look at an example.

Let's alter the JSON above to include a number field and an Array field.

{ "created_at": "2023-04-27T20:46:14.895+00:00", "created_by": "0c8e8409-f65b-4c97-891f-3c027af782d2", "first_name": "Jonny", "last_name": "Depp", "phone_number": "+123456789", "age": 60 "movies": [ "Pirates of the Caribbean", "Sleepy Hollow" ] }

As you can see we've added a number and an array. Now that we know what the initial values would be, when the response returns empty values for both "age" and "movies" the plugin alters the response first with proper empty values.

For example when the "movies" field is null instead it changes that to [] (empty array), this will help Bubble to better parse the incoming data.

Last updated