You are here

function hook_rest_server_execute_errors_alter in Services 7.3

Same name in this branch
  1. 7.3 docs/services.alter.api.php \hook_rest_server_execute_errors_alter()
  2. 7.3 servers/rest_server/rest_server.api.php \hook_rest_server_execute_errors_alter()

Alter error messages right before delivering.

Parameters

array $errors: Array of following properties: 'code' -- error code 'header_message' -- message that will be returned in Status header 'body_data' -- data returned in the body of the response You can alter 'header_message' and 'body_data' in your hook implementations.

type $controller: Executed controller.

type $arguments: Arguments of the controller.

1 invocation of hook_rest_server_execute_errors_alter()
RESTServer::handleException in servers/rest_server/includes/RESTServer.inc
Set proper header and message in case of exception.

File

servers/rest_server/rest_server.api.php, line 53
Hooks provided by Services for the definition of servers.

Code

function hook_rest_server_execute_errors_alter(&$error, $controller, $arguments) {
  $error_code = $error['code'];
  if (user_is_logged_in() && $error_code == 401) {
    global $user;
    $error['header_message'] = '403 ' . t('Access denied for user @user', array(
      '@user' => $user->name,
    ));
  }
}