Skip to content

Improper error handling for method with no return type #204

@dalewking

Description

@dalewking

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 }
        )

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions