Http::get_class( int|bool $code ): string

In this article

Get the correct exception class for a given error code

Parameters

$codeint|boolrequired
HTTP status code, or false if unavailable

Return

string Exception class name to use

Source

public static function get_class($code) {
	if (!$code) {
		return StatusUnknown::class;
	}

	$class = sprintf('\WpOrg\Requests\Exception\Http\Status%d', $code);
	if (class_exists($class)) {
		return $class;
	}

	return StatusUnknown::class;
}

User Contributed Notes

You must log in before being able to contribute a note or feedback.