question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Response.statusCode returns -1

See original GitHub issue

Bug Report

Description

I’m not sure if this could be considered a bug, but what happens to me is that sometimes when I send a post request then the response statusCode is -1. This value is only returned when the post request is not sent to the destination.

What does this -1 value mean? Because it is not a http response code.

This is my method:

internal fun sendHttpPostRequest(TAG: String, endpoint: String): Promise<Long, Exception> {
        LogManager.info(TAG,"sendHttpPostRequest()")

        var statusCode: Int
        val def = deferred<Long, Exception>()

        try{
            Fuel.post(endpoint).response { request, response, _ ->
                LogManager.info(TAG, "Endpoint msg sent: ${request.url}")
                statusCode = response.statusCode

                if(statusCode == 200) {
                    LogManager.info(TAG, "Response: $statusCode - OK")
                    val data = String(response.data)
                    LogManager.info(TAG, "Response message: $data")
                }else{
                    LogManager.info(TAG, "Something wrong happened sending message. Response: $statusCode")
                }
                def.resolve(statusCode.toLong())
            }
        }catch (exception: Exception){
            LogManager.info(TAG, "Exception thrown! ${exception.stackTrace}")
            def.reject(exception)
        }

        return def.promise
    }

Environment

Development Machine

Complete the following information if applicable

  • OS: [Windows 10]
  • IDE: [Android Studio]
  • Fuel version: [fuel-android:1.15.0]
  • Kotlin version: [1.2.61]

Smartphone or Emulator

Complete the following information if applicable

  • Device: [Huawei Watch 2]
  • OS: [Android 8.0.0 and Wear OS 2.0]

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
SleeplessBytecommented, Jan 31, 2019

You can probably actually capture this:

Fuel.post(endpoint)
  .response { request, response, result ->
      val (bytes, error) = result
      if (error != null) {
        // here you have a wrapped error in FuelError that will tell you why the request failed. 
      }
  }

// Alternative way
Fuel.post(endpoint)
  .response { request, response, result ->
    when (result) {
      is Result.Failure -> {
        val ex = result.getException()
      }
      is Result.Success -> {
        val data = result.get()
      }
  }

Check here how you can use our result. Note: you need to manually import this or it will use kotlin’s built in result.

0reactions
angelrc96commented, Jan 31, 2019

Got it @SleeplessByte . So it’s like a default value that is returned when something went wrong sending the request. I was doing some tests and I found out that it’s due to Android Doze mode. Because sometimes network requests are delayed and once the task gets back the CPU, it doesn’t have network connection or something like that

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Returning http status code from Web Api controller
.net core 2.2 returning 304 status code. This is using an ApiController. ... NotAcceptable, new { data = model, error = "The ID...
Read more >
Frequently Used Status Code And How To Return Them From ...
In this article, you will learn frequently used status code and how to return them from ASP.NET Core Web API.
Read more >
Controller action return types in ASP.NET Core web API
A 404 status code is returned when the product represented by id doesn't exist in the underlying data store. The NotFound convenience method ......
Read more >
HTTP/1.1: Status Code Definitions
This class of status code indicates that the client's request was successfully received, understood, and accepted. 10.2.1 200 OK. The request has succeeded....
Read more >
Return HTTP Status Code from ASP.NET Core Methods
It is advisable to return the proper HTTP status code in response to a client request. This helps the client to understand the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found