Call onCompleted only when the server response code is >= 200 and < 400
See original GitHub issueActually the onError
callback gets called only if the request cannot reach the server due to networking errors, even after the retries.
If the request successfully reaches the server, the onCompleted
gets called with the server’s response.
This has to be changed, because it’s not intuitive and practical for error handling when the server responds with http codes which indicate errors, such as 4xx
or 5xx
and does not allow to show the error message configured for the notification.
The callback methods should be called in this way:
onCompleted
when the server responds with an HTTP code >= 200 and < 400onError
if the request could not reach the server or if the server responds with a code >= 400
This means changing the public API of the callback’s onError
method, which will be the following:
/**
* Called when an error happens during the upload, after that all the retries have been
* completed without success. Override this method to add your own logic.
*
* @param context context
* @param uploadInfo upload status information
* @param serverResponse response got from the server
* @param exception exception that caused the error
*/
void onError(final Context context, final UploadInfo uploadInfo,
final ServerResponse serverResponse, final Exception exception);
This issue is open for discussion
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Error Policy in Apollo Client React seems doesn't work - Help
You're encountering a 400 error which means the server can't return any data, because it doesn't understand your query.
Read more >Handling errors with react-apollo useMutation hook
A network error will occur when a server can't be reached or if the response status is anything other than 200 -- queries...
Read more >Skip in React useQuery is not respected and onCompleted is ...
The result of the network request was 400 - Bad request but onError has not been called; Button Europe : The query is...
Read more >HttpURLConnection - Android Developers
It will return 200 and 401 respectively. Returns -1 if no code can be discerned from the response (i.e., the response is not...
Read more >Get your C# WebAPI controller to keep processing a request ...
The key is the "Response.OnCompleted" part, which allows your code to execute even after reporting HttpStatus 200 OK to the client. Top comments ......
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 Free
Top 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
Actually, I think it can solve the problem, and I’m going to explain why IMHO.
When implementing whatever endpoint, you should always follow the HTTP Status codes definition in RFC2616 to be standard compliant and to not reinvent the wheel.
Fail fast
is a good approach when dealing with requests to a server. If the client is not allowed to perform an action, you should kick it as soon as possible. Following the RFC, to implement your example, you should simply return413 Request Entity Too Large
and not accept the request at all, so you don’t consume network bandwidth and resources both on the client and the server. When you have to check the length of the upload, always use fixed length streaming mode on the client, which is supported by Upload Service. This results in theContent-Length
header being sent in the request, so you can inspect it on the server and act accordingly.You can always return a response body with HTTP status
4xx
. In fact, if you have more complex checks which does not match any of the4xx
error codes, practice suggests to send a400 Bad Request
with the error detail in the response body.E.g.:
HTTP Status: 400 Bad Request
Response body:Let’s examine a more complex scenario. You upload a file which has to be validated by the server after it has been uploaded. You let the client perform the upload, and after it has been completed you perform the server-side checks. After the checks have been performed, you return a
2xx
if everything is ok or a4xx
with all the relevant details which tells the client exactly what has gone wrong.Having said that, I like your idea to be able to modify the notification message from the callbacks, because it allows you to display more details to the user after the request has been completed (either successfully or with an error), though I’m not sure if it’s possible with the actual architecture, because each upload task manages its own notification and then sends broadcasts to notify the status outside the task.
This is getting OT here as new ideas comes. Let’s continue the discussion about notifications on #260