Forum Discussion

PerBonomi's avatar
10 years ago

api call should fail, but gives success

Hi there, I'm trying to catch an error, but instead I get success; help?

 

Using this url, I get the appropriate response, error 100 "Please enter a subject":

https://community.spotify.com/restapi/vc/boards/id/spotifywelcome/messages/post?message.subject=

 

But doing the same with ajax I get a 200 OK response and console logs "success." Clearly I must be doing something wrong, but what? :)

 

Ajax:

$.ajax({
	type: "POST",
	url: "/restapi/vc/boards/id/spotifywelcome/messages/post?message.subject="
})
.success(function() {
	console.log("success");
})
.fail(function() {
	console.log("fail");
});
  • Hi @PerBonomi,

     

    I did the same Ajax call. Just consoled the data in success.

    img 1.PNG

    And found this in console.

    img 3.PNG

    Which supports what PaoloT is saying.

    I don't know your use case. But if your use case is to find such error condition then you can do one thing.

    You can parse the xml in success itself and check the status and error code of response and then write your code in that condition. 

     

    Thank you.

     

    Regards,

    Vishwajeet.

     

    • PaoloT's avatar
      PaoloT
      Lithium Alumni (Retired)

      I would also suggest to use restapi.response_format=json as a call parameter, as JSON is easier to play with in Javascript than XML.

       

  • PaoloT's avatar
    PaoloT
    Lithium Alumni (Retired)

    Hi PerBonomi

     

    If you open that URL in the browser, you are in fact issuing a GET request, whereas your Javascript code is issuing a POST request. I am not sure why you get a different message (something you will want to report to our Support department for investigation) however that's the only difference I can tell between the two examples you provided (assuming you tried both with the same logged in user etc...).

     

    Please also note that jQuery's definition of "success" is not necessarily not be the same as the Lithium one. The call is successfull from jQuery's perspective (it was issued and it returned an HTTP 200 code),  but Lithium may have reurned data which indicates an error within our platform. I think REST v1 returns HTTP 200 most of the time (whereas REST v2 is in line with the HTTP semantics)

     

    Finally , these calls are being deprecated in the latest versions of jQuery so you may be better off using done, fail and always.

     

    Thanks,