Automattic\WooCommerce\Api\Infrastructure
GraphQLControllerBase::pick_status
Filter the framework-computed default HTTP status through the optional plugin-supplied status resolver.
When no resolver is configured this returns the default verbatim. When a resolver is configured its return value (an int) is returned in place of the default — which the resolver may also pass through unchanged for cases it does not want to override.
Resolver-thrown exceptions are converted into an internal StatusResolverFailedException{} for {@see self::handle_request()} to handle, so a plugin bug never corrupts or duplicates a response.
Method of the class: GraphQLControllerBase{}
No Hooks.
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->pick_status( $default, $output, $request ): int;
- $default(int) (required)
- The framework-computed default status.
- $output(array) (required)
- The response body about to be sent (may include
errors/data). - $request(WP_REST_Request) (required)
- The originating request.
GraphQLControllerBase::pick_status() GraphQLControllerBase::pick status code WC 10.9.1
private function pick_status( int $default, array $output, \WP_REST_Request $request ): int {
if ( null === $this->status_resolver ) {
return $default;
}
// phpcs:disable WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Internal sentinel; never serialised to the wire.
try {
$resolved = $this->status_resolver->resolve_status( $default, $output, $request );
} catch ( \Throwable $e ) {
throw new StatusResolverFailedException( 'HTTP status resolver threw.', 0, $e );
}
// Guard against nonsensical return values. Range-checking outside the
// try/catch keeps this exception out of the generic-Throwable wrap
// above, so a bad return value surfaces as the same fixed-shape 500
// response as a throw — never as a malformed WP_REST_Response.
if ( $resolved < 100 || $resolved > 599 ) {
throw new StatusResolverFailedException(
sprintf( 'HTTP status resolver returned an out-of-range status code: %d.', $resolved )
);
}
// phpcs:enable WordPress.Security.EscapeOutput.ExceptionNotEscaped
return $resolved;
}