Automattic\WooCommerce\Api\Infrastructure
GraphQLControllerBase::get_error_status
Determine the HTTP status code from an array of GraphQL errors.
Applies the code-to-status lookup to each error and returns the worst (highest) status seen. A single genuine 5xx among mixed errors surfaces as 500, which is the more useful signal for monitoring and logs.
Method of the class: GraphQLControllerBase{}
No Hooks.
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->get_error_status( $errors ): int;
- $errors(array) (required)
- The GraphQL errors array.
GraphQLControllerBase::get_error_status() GraphQLControllerBase::get error status code WC 10.9.1
private function get_error_status( array $errors ): int {
$status = 200;
foreach ( $errors as $error ) {
$code = $error['extensions']['code'] ?? null;
$mapped = self::ERROR_STATUS_MAP[ $code ] ?? 500;
if ( $mapped > $status ) {
$status = $mapped;
}
}
return $status;
}