Add exception handling

When calling the API via hook_menu(), exceptions should be converted to a JSON with HTTP error code, message and description.