The server has been parsing in JSON format through async asynchronous communication. However, sometimes if the server is being checked or there is a problem with the server, an error appears immediately after about a second, and it is forced to terminate. When there is a problem with the server, I want to tell you that it is not a forced shutdown, but a server problem in a dialog or other way, but how should I do it? Should I setconnecttimeout in async background? If you set the timeout as 10 seconds, you don't know where to code after 10 seconds. Is it on the post?
android android-asynctask json exception
The best way to do this is to drop the promised status code that the server is checking, and to send a dialog when the client receives the code.
And if an error occurs in the server, it is forcibly terminated.This is because there is an exception. If an error occurs, treat the exception as try-catch. Or check if the error can be checked with HTTP status code.
For example, the Github API drops the error with the HTTP status code and displays the error contents with the Response body: If the server API is defined as below, if the status code is classified as an error, the client can perform the process of showing the contents of the message as a pop-up.
HTTP/1.1 422 Unprocessable Entity
Content-Length: 149
{
"message": "Validation Failed",
"errors": [
{
"resource": "Issue",
"field": "title",
"code": "missing_field"
}
]
}
In summary, check if there is any information that can be recognized as an error in the server response, and then express the error situation properly in the UI accordingly. I don't want to recommend it because it seems to be too roundabout and difficult to completely handle the error.
© 2024 OneMinuteCode. All rights reserved.