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

Improper error handling for method with no return type #204

Open
dalewking opened this issue Jul 27, 2023 · 5 comments
Open

Improper error handling for method with no return type #204

dalewking opened this issue Jul 27, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@dalewking
Copy link

We have a delete call for an endpoint. So in the apI it is defined as a delete call so the key parts of the swagger are:

      "delete" : {
         ...
        "produces" : [ "application/json" ],
        "parameters" : [ {
          "name" : "deviceToken",
          "in" : "query",
          "description" : "Device token for app.",
          "required" : true,
          "type" : "string"
        } ],
        "responses" : {
          "204" : {
            "description" : "Success was deleted"
          },
          "400" : {
            "description" : "The request could not be understood by the server due to malformed syntax.",
            "schema" : {
              "$ref" : "#/definitions/ErrorBody"
            },
            "x-inin-error-codes" : {
              "bad.request" : "The request could not be understood by the server due to malformed syntax.",
              "response.entity.too.large" : "The response is over the size limit. Reduce pageSize or expand list to reduce response size if applicable"
            }
          },

So there is no actual data returned on success just a 204 status code. Errors can have a body though

The code that is generated looks something like this:

    override public open suspend fun deleteFoo(deviceToken: kotlin.String) : kotlin.Unit {
        try {
            deleteNotificationsPushRegistrationsResponse(deviceToken)
        } catch (pipeline: ReceivePipelineException) {
            throw pipeline.cause
        }
    }

    override public open suspend fun deleteFooResponse(deviceToken: kotlin.String) : kotlin.Unit {
        val builder = HttpRequestBuilder()

        .../

        with(builder.headers) {
            append("Accept", "application/json")
        }

        val response = _httpClient.request(builder)

    }

My initial complaint is that generates a warning when compiled about Variable 'response' is never used

But in reality isn't this code not going to handle error codes? Won't it eat the error and just always return unit?

Shouldn't the Response method return a NetworkResponse? The end of the response method could be something like:

        val response = _httpClient.request(builder)

        return NetworkResponse(
            httpResponse = response,
            bodyReader = { Unit }
        )
@Alex009 Alex009 added the bug Something isn't working label Jul 30, 2023
@Alex009 Alex009 added this to the 0.21.1 milestone Jul 30, 2023
@Code-indomitus
Copy link

Can I try to work on this?

@Alex009
Copy link
Member

Alex009 commented Oct 11, 2023

Can I try to work on this?

Yes! Please :)

@Code-indomitus
Copy link

Hi, I forked the repository and opened it in android studio. After building the project for some reason the platform and iOS-related imports are all marked red and "could not resolve reference" any idea how can I solve this? I am new to kotlin multiplatform actually.

@Alex009 Alex009 removed this from the 0.21.1 milestone Feb 25, 2024
@H4kt
Copy link

H4kt commented Jul 25, 2024

Hi, I forked the repository and opened it in android studio. After building the project for some reason the platform and iOS-related imports are all marked red and "could not resolve reference" any idea how can I solve this? I am new to kotlin multiplatform actually.

KMP iOS binding are currently only available on MacOS

@H4kt
Copy link

H4kt commented Jul 25, 2024

Any chance on this getting fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants