1313use GuzzleHttp \Exception \ServerException ;
1414use OC \Http \Client \Response ;
1515use OCA \Tables \Db \Share ;
16+ use OCA \Tables \Errors \FederationRequestError ;
1617use OCP \AppFramework \Http ;
1718use OCP \Federation \ICloudFederationFactory ;
1819use OCP \Federation \ICloudFederationProviderManager ;
@@ -70,7 +71,7 @@ protected function prependProtocolIfNotAvailable(string $url): string {
7071
7172 /**
7273 * @param 'get'|'post'|'put'|'delete' $verb
73- * @throws \Exception
74+ * @throws FederationRequestError
7475 */
7576 protected function request (
7677 string $ verb ,
@@ -93,17 +94,16 @@ protected function request(
9394 $ body ->rewind ();
9495
9596 if (!is_array (json_decode ($ content , true ))) {
96- throw new \ Exception ('Error parsing JSON response ' , $ status );
97+ throw new FederationRequestError ('Error parsing JSON response ' , $ status );
9798 }
9899
99100 $ this ->logger ->debug ('Client error from remote ' , ['exception ' => $ e ]);
100101
101102 /** @psalm-suppress InvalidReturnStatement */
102103 return new Response ($ e ->getResponse (), false );
103104 } catch (ServerException |\Throwable $ e ) {
104- $ serverException = new \Exception ($ e ->getMessage (), $ e ->getCode (), $ e );
105- $ this ->logger ->error ('Could not reach remote ' , ['exception ' => $ serverException ]);
106- throw $ serverException ;
105+ $ this ->logger ->error ('Could not reach remote ' , ['exception ' => $ e ]);
106+ throw new FederationRequestError ('Could not reach remote: ' . $ e ->getMessage (), $ e ->getCode (), $ e );
107107 }
108108 }
109109
@@ -123,6 +123,9 @@ public function delete(string $shareToken, string $url): IResponse {
123123 return $ this ->request ('delete ' , $ shareToken , $ url );
124124 }
125125
126+ /**
127+ * @throws FederationRequestError
128+ */
126129 public function getOCSData (IResponse $ response , array $ allowedStatusCodes = [Http::STATUS_OK ]): array {
127130 if (!in_array ($ response ->getStatusCode (), $ allowedStatusCodes , true )) {
128131 $ this ->logger ->debug ('Unexpected status code ' . $ response ->getStatusCode ());
@@ -132,11 +135,11 @@ public function getOCSData(IResponse $response, array $allowedStatusCodes = [Htt
132135 $ content = $ response ->getBody ();
133136 $ responseData = json_decode ($ content , true , flags: JSON_THROW_ON_ERROR );
134137 if (!is_array ($ responseData )) {
135- throw new \ RuntimeException ('JSON response is not an array ' );
138+ throw new FederationRequestError ('JSON response is not an array ' );
136139 }
137140 } catch (\Throwable $ e ) {
138141 $ this ->logger ->error ('Error parsing JSON response ' , ['exception ' => $ e ]);
139- throw new \ Exception ('Error parsing JSON response ' , $ e ->getCode (), $ e );
142+ throw new FederationRequestError ('Error parsing JSON response ' , $ e ->getCode (), $ e );
140143 }
141144
142145 return $ responseData ['ocs ' ]['data ' ] ?? [];
0 commit comments