In RESTServer.inc all "services_errors"/"ServicesExceptions" after the call to the services controller are handled correctly and displayed in the right format as they are going through renderFormatterView():

    try {
      $result = services_controller_execute($controller, $arguments, $options);
    }
    catch (ServicesException $e) {
      $result = $this->handleException($e);
    }
    // Set the content type and render output
    drupal_add_http_header('Content-type', $mime_type);
    return $this->renderFormatterView($controller, $formatter, $result);

However, any errors before this is executed will only return an error message in the header, with an empty body.

In the call to getControllerArguments() one of these errors includes:

services_error(t('Missing required argument @arg', array('@arg' => $info['name'])), 401);

By the time we get to the arguments we already know the controller and the formatter so we might as well display this error message in the right format through renderFormatterView().

I included a patch which does the following things:

- Expand the try/catch so we can catch the "Missing required argument" services_error.
- Move "$arguments = $this->getControllerArguments($controller, $path, $method);" downwards, so that if there is an exception within getControllerArguments the formatters have already been set up and we can display the error correctly through renderFormatterView().

Two lines have been changed and a comment has been added, the rest are indentation changes to allow for the expanded "try" block.

Steps to reproduce:

1. Set up a resource with a required argument.
2. Go to the URL of the resource and notice how the error message is only displayed in the header and the body is empty.

To further clarify, the following error messages are executed before the call to the services controller as well and are not displayed in the body either:

services_error(t('Could not find the controller.'), 404);
services_error(t('Could not find resource @name.', array('@name' => $resource_name)), 404);
services_error(t('Unknown or unsupported response format.'), 406);

We don't know what format to display these in (ie. XML/JSON), so it makes sense to only show the error in the header. Perhaps we could output these in a standard drupal HTML error page in addition to showing the error in the header?

Comments

stefan.r’s picture

Issue summary: View changes

typo

stefan.r’s picture

Issue summary: View changes

plaintext won't work

ygerasimov’s picture

Status: Active » Needs review
StatusFileSize
new1005 bytes

For displaying arguments handling errors we can have patch attached. For having others I would need to do some refactoring to fix that.

Attaching patch to check tests.

kylebrowning’s picture

Version: 7.x-3.3 » 7.x-3.x-dev
kylebrowning’s picture

Status: Needs review » Reviewed & tested by the community

This looks good, open another issue as a feature request for better error handling messages.

ygerasimov’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.2 KB

Here is reroll of the patch. If it is green, I will commit it.

Status: Needs review » Needs work

The last submitted patch, services-1937312-format-arguments-errors-reroll-4.patch, failed testing.

POVYLAZZZ’s picture

Status: Needs work » Needs review
kylebrowning’s picture

Status: Needs review » Needs work

needs another re-roll.

ygerasimov’s picture

Status: Needs work » Needs review
StatusFileSize
new806 bytes

Patch reroll.

ygerasimov’s picture

Status: Needs review » Fixed

Committed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

clarification