GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing docs.php-http.org — Error Plugin — PHP-HTTP 1.0.0 documentation Error PluginThe
Warning Throwing an exception on a valid response violates the PSR-18 specification. This plugin is provided as a convenience when writing a small application. When providing a client to a third party library, this plugin must not be included, or the third party library will have problems with error handling. Both exceptions extend the use Http\Discovery\HttpClientDiscovery; use Http\Client\Common\PluginClient; use Http\Client\Common\Plugin\ErrorPlugin; use Http\Client\Common\Exception\ClientErrorException; $errorPlugin = new ErrorPlugin(); $pluginClient = new PluginClient( HttpClientDiscovery::find(), [$errorPlugin] ); ... try { $response = $pluginClient->sendRequest($request); } catch (ClientErrorException $e) { if ($e->getResponse()->getStatusCode() == 404) { // Something has not been found } } The error plugin is intended for when an application operates with the client directly. When writing a library around an API, the best practice is to have the client convert responses into domain objects, and transform HTTP errors into meaningful domain exceptions. In that scenario, the ErrorPlugin is not needed. It is more efficient to check the HTTP status codes yourself than throwing and catching exceptions. If your application handles responses with 4xx status codes, but needs exceptions for 5xx status codes only,
you can set the option $errorPlugin = new ErrorPlugin(['only_server_exception' => true]); |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |