File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed
Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -143,16 +143,22 @@ public function create($doc)
143143 public function getDocById ($ id ) : Document
144144 {
145145 $ endpoint = "/ " . $ this ->db_name . "/ " . $ id ;
146- $ response = $ this -> client -> request ( " GET " , $ endpoint );
147- if ( $ response-> getStatusCode () == 200 ) {
146+ try {
147+ $ response = $ this -> client -> request ( " GET " , $ endpoint );
148148 if ($ data = json_decode ($ response ->getBody (), true )) {
149149 $ doc = new Document ($ this , $ data );
150150 return $ doc ;
151151 } else {
152152 throw new Exception \ServerException ('JSON response not received or not understood ' );
153153 }
154- } else {
155- throw new Exception \DatabaseException ('Document not found ' );
154+ } catch (\GuzzleHttp \Exception \ClientException $ e ) {
155+ $ status = $ e ->getResponse ()->getStatusCode ();
156+ if ($ status == 404 ) {
157+ // not really a disaster, the doc just isn't there so throw specific exception
158+ throw new Exception \DocumentNotFoundException ('Document not found ' );
159+ } else {
160+ throw new Exception \DatabaseException ('The document could not be retrieved ' , 0 , $ e );
161+ }
156162 }
157163 }
158164}
You can’t perform that action at this time.
0 commit comments