Handling get response while server has been crashed - javascript

I have a question.
I send a Get request by Ajax every second and expect to get some response from the server.
In the case and my application crashes and I continue to send Get request every second, I don't get any response until receiving the server's timeout error (an error code 502.) .
If somebody knows how I can handle this moment between sending the get requests every second and until receiving error code 502.
Thanks

If the server is down, whatever you are using for the ajax call should have errored out... in which case you should handle it with a call back or a catch block. There, you should handle what you will do on the frontend based on the response.
As far as not sending out more requests, there really is no way to know for sure. For all your code knows, the server is particularly slow at that moment.

Related

HTTP request timeout and content download time

I'm having a weird issue about HTTP requests...
The request is marked as "Pending" under the network and eventually a timeout happens. The timing tab shows this
The weird thing about this is that if I execute the exact, same HTTP request a second time it gets processed in 500ms and I correctly get the requested data.
Does someone know how this can happen and how can this be fixed?
Thank you!!
For those who are still looking for this, it happened that due to a coding error AngularJS started to trigger a huge amount of digests that blocked the client to get the HTTP response.

Custom HTTP response hanlder in Datatables.js

I am currently using Datatables.js to fetch and show data. Everything is OK.
But there might be some cases where Datatables.js has to deal with failed HTTP requests because the server decides not to send data back.
For example, checking against a user's identity, the server decides that this user is not authorized to see next page of data and send error messages back alongside with 401 status code.
The problem is that whenever Datatables.js receives a non-200 response, it will generate an alert box saying "Datatables warning:...".
Is there a way to intercept this process, provide custom handlers to Datatables.js when it encounters those HTTP responses e.g. 401, 404 , displaying error message in whatever way I want?
Thank you.

Process reponse data when getting a non HTTP 2xx answer with appAPI.request

I'm using appAPI.request to make ajax calls to an external web API. This works very well, but the API sends HTTP status codes other than 200 when something goes wrong. It also sends the error message/code when this happens. As the onFailure callback does only returns the http error code, but not the response message, i'm unable to read the error message sent by the server. Is there any way to retrieve the response message when onFailure gets called?
As of now, the HTTP response text is not currently available in the onFailure callback. However, as we are constantly working on improvements, we will add this to our API in future releases.
Disclaimer: I am a Crossrider employee

Browser mangling 302 responses from Ajax requests

I have the following.
AJAX request made to server from mydomain.blah.com
Server returns 302 but to a slight different domain blah.com not mydomain.blah.com
Browser appears to mangle response. Instead of the 302 coming into my error callback a response with no response body and no status code is returned.
Further details
Looking at request in IE 10 it is marked as aborted.
In FF , firebug shows the 302 coming back but it never been handled.
To complicate matters (although I don't this is relevant) there are multiple ajax requests sent over.
The reason why the 302 is returned is because my server session is timed out and I am being redirected to a login page. I don't have much control over the server.
I want to get the response code 302 sent from my server into my error callback. This is what I want to achieve.
The ajax calls are being made using JQuery.
Any help appreciated.
If it is offical policy for browsers to "mangle" 302 responses to difference domains from ajax calls then if anyone could provide a reference that would be cool. Then I'd know there is not much I can do about this.

Performing GET request before leaving page

If a GET request is made as follows
$(window).bind('beforeunload', function() {
// GET request
});
and the page is abandoned before the GET request is completed,
will the destination server still process the request? Or will it somehow vanish?
I would like to send a server data on beforeunload firing, but without stealing useless ms from the user.
It would be very useful if someone could help me.
If it is an asynchronous request then the server may process it (if it receives the request) but I don't know if you can guarantee that the request will go through before the page is unloaded or if it will be processed - this may depend on the actual web server (someone else may have more information). If you make a synchronous request, the page will wait until the request goes through and it gets back a response (so in this case, processing is guaranteed). However, this means that your browser will be locked up until that request completes, which may not be desirable.
In most cases yes, but it depends on the web application server. Some can detect the disconnect and stop with the request.

Categories

Resources