Basically I written a REST service and my business logic requires me to validate the input. For instance make sure the format of phone number is (###)###-####. If it is not, it should return invalid phone number. Further more I need to record all actions of the service. So when the client queries the system, they can find out what was the last action. I.e:
ACTION: ADD – SUCCESS
ACTION: ADD – INVALID PHONE NUMBER
So now I’m thinking whether I need to create my own custom error codes or just use the default HTTP ones and also record those inside the “log”
Pretty new to REST style so if my logic is off let me know…
So should I…
public void callPerson(String phone)
{
try
validate(phoneNumber)
call person
catch
throw Invalid Phone Number
finally
record status to DB
}
or
public myStatusCode callPerson(String phone)
{
try
validate(phoneNumber)
call person
catch
return myStatusCode
finally
record status to DB
}
In fact I also want to make sure the status gets recorded as well other wise it would not be good if say the action worked but the status update didn’t. So updating the status should really be part of the “transaction”
Also another thing to keep in mind this REST service some of the actions have to communicate with an older “message” oriented service where the response and error code are in the XML response message…
Any suggestions? Thanks
I would recommend a HTTP status code 412 (Precondition Failed) and a String message for the error.