Web Connection
Return JSON error from wwRESTProcess method
Gravatar is a globally recognized avatar based on your email address. Return JSON error from wwRESTProcess method
  n/a
  All
  Sep 18, 2014 @ 05:33pm
I'm building a set of simple RESTful methods to allow an internal web application to query data from my WC app using jQuery AJAX.

I'm using the wwRestProcess class with some success, but can't seem to figure out how to return an error to the AJAX client. I'd like to return a useful error message if an invalid parameter is passed, for example.

The framework is returning errors encountered during serialization correctly, of course, but I'd like to be able to return at least the same error message that wwJsonService::ReturnExceptionObject returns:

[{"isCallbackError":true,"message":"] + lcMessage + ["}]

I'm not clear on how to effectively throw an exception in the RestProcess method that will return a JSON error to the client.

Thanks!


Steve

Gravatar is a globally recognized avatar based on your email address. Return JSON error from wwRESTProcess method
  n/a
  Steve Finch
  Sep 19, 2014 @ 01:27pm

I figured out that I can use This.ErrorResponse from a wwRestProcess method to correctly return the HTTP status code and error text to the AJAX client.


I'm building a set of simple RESTful methods to allow an internal web application to query data from my WC app using jQuery AJAX.

I'm using the wwRestProcess class with some success, but can't seem to figure out how to return an error to the AJAX client. I'd like to return a useful error message if an invalid parameter is passed, for example.

The framework is returning errors encountered during serialization correctly, of course, but I'd like to be able to return at least the same error message that wwJsonService::ReturnExceptionObject returns:

[{"isCallbackError":true,"message":"] + lcMessage + ["}]

I'm not clear on how to effectively throw an exception in the RestProcess method that will return a JSON error to the client.

Thanks!



Steve

Gravatar is a globally recognized avatar based on your email address. Return JSON error from wwRESTProcess method
  Rick Strahl
  Steve Finch
  Sep 22, 2014 @ 03:12pm
Steve,

This will get much better I'm the next release. The wwRestProcess class has been just a prototype until now. It works but there are rough edges.

The next release shortly will have improved integration much better error handling where you can just call ERROR "Your Error Message" and it will automatically return a JSON or XML error message. Basically any error in your code will result in a JSON error message returned to the client in the form of a errorResponse object (isCallbackError,message properties). These errors will carry a 500 result code. You can still return explict error codes by using THIS.ErrorResponse("error message","404 Not Found") to return specific HTTP error codes.

The new version can also return results as either JSON or XML based on the Accept: HTTP header.

There are lots of fixes and tweaks to this interface where everything works as it's supposed to - the previous prototype had a number of small bugs that have been worked through in the process of a few live implementations in the last half a year or so.

I'm hoping to get this release out next week as soon as I'm back in my office and have a day or two to wrap up the final packaging for the version update.

+++ Rick ---


I figured out that I can use This.ErrorResponse from a wwRestProcess method to correctly return the HTTP status code and error text to the AJAX client.


I'm building a set of simple RESTful methods to allow an internal web application to query data from my WC app using jQuery AJAX.

I'm using the wwRestProcess class with some success, but can't seem to figure out how to return an error to the AJAX client. I'd like to return a useful error message if an invalid parameter is passed, for example.

The framework is returning errors encountered during serialization correctly, of course, but I'd like to be able to return at least the same error message that wwJsonService::ReturnExceptionObject returns:

[{"isCallbackError":true,"message":"] + lcMessage + ["}]

I'm not clear on how to effectively throw an exception in the RestProcess method that will return a JSON error to the client.

Thanks!



© 1996-2024