Search code examples
restoracle-jet

Getting server response code in oracle jet web service call


I am calling a REST Webservice from Oracle jet ViewModel. The server response as I expected, but how to catch the server response (If the server response is like 400,422). I tried with the following lines of code, but it doesn't seem to be working.

               self.User = oj.Model.extend({
                    urlRoot : self.resourceUrl,
                    idAttribute : "userId"
                });

                var user = new self.User();
                user.save( 
                        {
                          success: function(user, response, options) {
                          console.log("response "+response);
                          },
                          error: function(jqXHR, textStatus, errorThrown) {
                            console.log("error thrwos "+errorThrown);
                            console.log("status "+textStatus);
                      }
                  });

All I want to do is, if server response is a success, show the user a success message and navigate to the next page and if the response is an error( 400 or 422 or whatever), show the user an error message ( this can be done using a validator).


Solution

  • Looking at the JSDocs for model.save http://www.oracle.com/webfolder/technetwork/jet/jsdocs/oj.Model.html#save

    You will see that you can define a callback function to handled the error returned by the save call.

    This would work with what @Koshinae is saying in his comment above about options.