I am trying to work out why the errorThrown text passed to the fail function is empty under some circumstances. Here's the jQuery test call which is intended to produce a failure:
$.get(
"/iams/api/v1/doesnotexist",
"",
function (response) {
alert("Got a response");
}
).fail(
function (jqXHR, textStatus, errorThrown) {
console.log('jqXHR:');
console.log(jqXHR);
console.log('textStatus = ' + textStatus);
console.log('errorThrown = ' + errorThrown);
alert('Check the console log.');
}
)
The server response as expected is:
HTTP/1.1 500 REST v1 API doesnotexist plug-in is missing!
Date: Wed, 25 Sep 2019 16:48:29 GMT
Server: Apache
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Upgrade: h2,h2c
Connection: Upgrade, close
Content-Length: 56
Content-Type: application/json
{"error":"REST v1 API doesnotexist plug-in is missing!"}
If I execute the test case with my local development server or with Fiddler running between me and my HostGator site, I get the expected errorThrown text of
REST v1 API doesnotexist plug-in is missing!
However, if I turn off Fiddler and execute against my HostGator server, the errorThrown text is empty.
Logging jqXHR, textStatus and errorThrown to the console on the live site I get:
test.php:39 jqXHR:
test.php:40 {readyState: 4, getResponseHeader: ƒ, getAllResponseHeaders: ƒ, setRequestHeader: ƒ, overrideMimeType: ƒ, …}abort: ƒ (a)always: ƒ ()complete: ƒ ()done: ƒ ()error: ƒ ()fail: ƒ ()getAllResponseHeaders: ƒ ()getResponseHeader: ƒ (a)overrideMimeType: ƒ (a)pipe: ƒ ()progress: ƒ ()promise: ƒ (a)readyState: 4responseJSON: {error: "REST v1 API doesnotexist plug-in is missing!"}responseText: "{"error":"REST v1 API doesnotexist plug-in is missing!"}"setRequestHeader: ƒ (a,b)state: ƒ ()status: 500statusCode: ƒ (a)statusText: "error"success: ƒ ()then: ƒ ()__proto__: Object
test.php:41 textStatus = error
test.php:42 errorThrown =
whereas with my development server or Fiddler in the middle with the live site I get the following with the correct errorThrown::
test.php:39 jqXHR:
test.php:40 {readyState: 4, getResponseHeader: ƒ, getAllResponseHeaders: ƒ, setRequestHeader: ƒ, overrideMimeType: ƒ, …}abort: ƒ (a)always: ƒ ()complete: ƒ ()done: ƒ ()error: ƒ ()fail: ƒ ()getAllResponseHeaders: ƒ ()getResponseHeader: ƒ (a)overrideMimeType: ƒ (a)pipe: ƒ ()progress: ƒ ()promise: ƒ (a)readyState: 4responseJSON: {error: "REST v1 API doesnotexist plug-in is missing!"}responseText: "{"error":"REST v1 API doesnotexist plug-in is missing!"}"setRequestHeader: ƒ (a,b)state: ƒ ()status: 500statusCode: ƒ (a)statusText: "REST v1 API doesnotexist plug-in is missing!"success: ƒ ()then: ƒ ()__proto__: Object
test.php:41 textStatus = error
test.php:42 errorThrown = REST v1 API doesnotexist plug-in is missing!
So jqXHR.statusText = "error" and errorThrown is empty with the live server and "
REST v1 API doesnotexist plug-in is missing!
" with my development server or Fiddler in the middle.
Both developent and live sites are using jQuery 1.11.2
Any suggestions on where to look would be much appreciated so I can make sure the correct error is shown to the user instead of a blank box! Thank you in advance.