0

Often there are situations where the server responses are 200OK, but the response content is not the expected one. Can we trigger the jquery ajax error callback, even if the response is success, based on some criteria in the response?

The response, in my case is a valid json, but not the expected response (schema validation failed), so not a json parsing error.

I'm looking forward to a solution, where the response is evaluated before it actually hits the success or error callbacks.

Tirtha
  • 862
  • 1
  • 12
  • 29

1 Answers1

0

Why do you need fail ajax? The error callback should use handle unknow exceptions.
If you want to know the server process result, just return different type message, then take different process in ajax success callback by message type.
If there is no exceptions, always process server result in success callback.

Bucketcode
  • 461
  • 2
  • 13
  • As I mentioned, The response, in my case is a valid json, but not the expected response, so not a json parsing error. – Tirtha Aug 22 '16 at 03:58
  • Check the marked of this question, it's what i mean. – Bucketcode Aug 22 '16 at 05:11
  • Its called contract driven development, useful while communicating with external microservices. You're answer isn't satisfactory. – Tirtha Sep 23 '17 at 09:43