Yoast\WP\SEO\MyYoast_Client\User_Interface
Management_Route::handle_exception
Maps an exception to a REST error response.
The REST endpoint itself executed correctly — what failed is an upstream call to MyYoast or a precondition. We therefore return HTTP 200 with an error_code in the body that the UI translates into actionable copy. Genuine request-validation failures return 4xx separately (see callers).
Метод класса: Management_Route{}
Хуков нет.
Возвращает
WP_REST_Response.
Использование
// private - только в коде основоного (родительского) класса $result = $this->handle_exception( $exception ): WP_REST_Response;
- $exception(Throwable) (обязательный)
- The exception to handle.
Код Management_Route::handle_exception() Management Route::handle exception Yoast 28.7
private function handle_exception( Throwable $exception ): WP_REST_Response {
if ( $exception instanceof Registration_Not_Found_Exception ) {
return $this->error_response( 'registration_gone', $exception );
}
if ( $exception instanceof Rate_Limited_Exception ) {
$retry_after = $exception->get_retry_after_seconds();
$details = ( $retry_after !== null ) ? [ 'retry_after_seconds' => $retry_after ] : [];
return $this->error_response( 'rate_limited', $exception, 200, $details );
}
if ( $exception instanceof Server_Capability_Exception ) {
return $this->error_response( 'server_capability', $exception );
}
if ( $exception instanceof Discovery_Failed_Exception ) {
return $this->error_response( 'myyoast_unreachable', $exception );
}
if ( $exception instanceof Token_Request_Failed_Exception ) {
$code = ( $exception->get_error_code() === 'invalid_grant' ) ? 'token_request_failed_invalid_grant' : 'token_request_failed';
return $this->error_response( $code, $exception );
}
if ( $exception instanceof Token_Storage_Exception ) {
return $this->error_response( 'token_storage_failed', $exception );
}
if ( $exception instanceof Invalid_Resource_Exception ) {
return $this->error_response( 'invalid_resource', $exception );
}
if ( $exception instanceof Registration_Failed_Exception ) {
return $this->error_response( 'registration_failed', $exception );
}
$this->logger->error(
'Unexpected exception in MyYoast management route: {message}',
[ 'message' => $exception->getMessage() ],
);
return $this->error_response( 'unexpected_error', $exception );
}