aam_rest_get_error_response_filter

Purpose

Provide a REST error response for premium handlers. Premium.

Callback

Example

add_filter('aam_rest_get_error_response_filter', function ($response, $exception) {
    if ($response === null && $exception instanceof InvalidArgumentException) {
        return new WP_Error('myapp_bad_request', $exception->getMessage(), ['status' => 400]);
    }
    return $response;
}, 10, 2);

Converts one exception type to a REST error and preserves a response already supplied by another callback.

See the complete hook list.