Saran
Saran

Reputation: 3884

jQuery doesn't fire $.ajax.fail() when Mockjax returns status:500 (or 400 or...)

Mockjax setup:

$.mockjax({
  url: "/api/get",
  responseTime: 100, // default: 500
  dataType: "json",
  data: { action: "all" },
  proxy: "data.json",
  status: 400
});

The call to mockjax:

$.ajax({
  url: '/api/get',
  dataType: "json",
  data: { action: "all" }
})
.always(function() {
  //something
})
.done(function(json) {
  console.log("done");
})
.fail(function() {
  console.log("error");
});

The mockjax properly returns the (JSON) data, but the problem is that always the done() callback is called (and never the fail()), regardless of mockjax status number set.

But if I intentionally set the bad proxy path, only then the fail() is fired.

What gives?

Upvotes: 1

Views: 1029

Answers (2)

Saran
Saran

Reputation: 3884

The problem is fixed in Mockjax v1.5.3.

Upvotes: 1

Saran
Saran

Reputation: 3884

Until the mockjax issue is resolved, here are (some) workarounds that fire $.ajax.fail() callback:

  • isTimeout: true
  • malformed proxy: path

Upvotes: 0

Related Questions