Response.statusCode returns -1
See original GitHub issueBug 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:
- Created 5 years ago
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You can probably actually capture this:
Check here how you can use our result. Note: you need to manually import this or it will use kotlin’s built in result.
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