jmcx / restlet-contacts-app

A simple contact list app built with Restlet
0 stars 0 forks source link

Check for error in response to contact creation #6

Open jmcx opened 11 years ago

jmcx commented 11 years ago

The server may return an error if the contact being created already exists. The client must integrate this response and inform the user.

templth commented 11 years ago

For such processing, you can throw a Restlet ResourceException within your server resources, as described below :

@Post
public Contact addContact(Contact contact) {
    if (contactExists(contact)) {
        throw new ResourceException(Status.CLIENT_ERROR_UNPROCESSABLE_ENTITY);
    }
}

Note that the Status.CLIENT_ERROR_UNPROCESSABLE_ENTITY corresponds the 422 status code.