Android Code Snippet ErrorResponse in OkHttpResponse of HttpUtils2Service may be JSON

Hi, All

Some server's API (say cloud storage Yandex.Disk) may generate the error with a code (say, 404), but JSON-encoded, like
B4X:
{"message":"The requested resource was not found.","description":"Resource not found.","error":"DiskNotFoundError"}

So, it's useful to update the code of HttpUtils2Service like here:

B4X:
Sub hc_ResponseError (Response As OkHttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
    If Response <> Null Then
        Log("hc_ResponseError=" & Response.ErrorResponse)
        Response.Release
    End If
    If Response.ContentType.Contains("json") Then
        Reason = Response.ErrorResponse
    End If
    CompleteJob(TaskId, False, Reason)
End Sub

to get full info about the error including the message for user.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…