Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request]: Include response in RestException #774

Open
2 tasks done
DominicGBauer opened this issue Nov 4, 2024 · 3 comments · May be fixed by #789
Open
2 tasks done

[Feature request]: Include response in RestException #774

DominicGBauer opened this issue Nov 4, 2024 · 3 comments · May be fixed by #789
Assignees
Labels
enhancement New feature or request

Comments

@DominicGBauer
Copy link

General Info

  • I installed the latest version of Supabase Kt
  • I checked for similar feature requests

Feature request

Please can the response be included in the RestException as I need access to the code that is in the response?

(Similar change happened here d3ee40f)

Usecase

I currently need to use this interceptor to get access to the code from the response to be used in my error catch:

        // This retrieves the error code from the response
        // as this is not accessible in the Supabase client RestException
        // to handle fatal Postgres errors
        supabaseClient.httpClient.httpClient.plugin(HttpSend).intercept { request ->
            val resp = execute(request)
            val response = resp.response
            if (response.status.value == 400) {
                val responseText = response.bodyAsText()

                try {
                    val error = Json { coerceInputValues = true }.decodeFromString<Map<String, String?>>(responseText)
                    errorCode = error["code"]
                } catch (e: Exception) {
                    Logger.e("Failed to parse error response: $e")
                }
            }
            resp
        }

Ideally, I could just do something like this

catch(e: Exception) {
     when (e) {
          is BadRequestRestException -> {
            (if e.code = some code) {
                 // Handle error
            }
      }
}
@jan-tennert
Copy link
Collaborator

Which module has this code error field? Postgrest?

@jan-tennert
Copy link
Collaborator

Alright, I think the best way is to add a custom exception for Postgrest (like the AuthRestException) exposing these properties.
But nonetheless, we can also expose the whole response in the RestExceptions in general.
I'll take a look at it and see if we can make it into 3.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants