2828use Kreait \Firebase \Auth \CustomTokenViaGoogleCredentials ;
2929use Kreait \Firebase \Auth \SignIn \GuzzleHandler ;
3030use Kreait \Firebase \Database \UrlBuilder ;
31+ use Kreait \Firebase \Exception \AppCheckApiExceptionConverter ;
32+ use Kreait \Firebase \Exception \AuthApiExceptionConverter ;
33+ use Kreait \Firebase \Exception \DatabaseApiExceptionConverter ;
3134use Kreait \Firebase \Exception \InvalidArgumentException ;
3235use Kreait \Firebase \Exception \MessagingApiExceptionConverter ;
36+ use Kreait \Firebase \Exception \RemoteConfigApiExceptionConverter ;
3337use Kreait \Firebase \Exception \RuntimeException ;
38+ use Kreait \Firebase \Http \ErrorResponseParser ;
3439use Kreait \Firebase \Http \HttpClientOptions ;
3540use Kreait \Firebase \Http \Middleware ;
3641use Kreait \Firebase \JWT \IdTokenVerifier ;
@@ -119,6 +124,8 @@ final class Factory
119124
120125 private HttpClientOptions $ httpClientOptions ;
121126
127+ private ErrorResponseParser $ errorResponseParser ;
128+
122129 /**
123130 * @var array<non-empty-string, mixed>
124131 */
@@ -139,6 +146,7 @@ public function __construct()
139146 $ this ->defaultCache = new InMemoryCache ($ this ->clock );
140147 $ this ->httpFactory = new HttpFactory ();
141148 $ this ->httpClientOptions = HttpClientOptions::default ();
149+ $ this ->errorResponseParser = new ErrorResponseParser ();
142150 }
143151
144152 /**
@@ -375,7 +383,7 @@ public function createAppCheck(): Contract\AppCheck
375383 );
376384
377385 return new AppCheck (
378- new AppCheck \ApiClient ($ http ),
386+ new AppCheck \ApiClient ($ http, new AppCheckApiExceptionConverter ( $ this -> errorResponseParser ) ),
379387 new AppCheckTokenGenerator (
380388 $ serviceAccount ->clientEmail ,
381389 $ serviceAccount ->privateKey ,
@@ -392,7 +400,14 @@ public function createAuth(): Contract\Auth
392400 $ httpClient = $ this ->createApiClient ();
393401
394402 $ signInHandler = new GuzzleHandler ($ projectId , $ httpClient );
395- $ authApiClient = new ApiClient ($ projectId , $ this ->tenantId , $ httpClient , $ signInHandler , $ this ->clock );
403+ $ authApiClient = new ApiClient (
404+ $ projectId ,
405+ $ this ->tenantId ,
406+ $ httpClient ,
407+ $ signInHandler ,
408+ $ this ->clock ,
409+ new AuthApiExceptionConverter ($ this ->errorResponseParser ),
410+ );
396411 $ customTokenGenerator = $ this ->createCustomTokenGenerator ();
397412 $ idTokenVerifier = $ this ->createIdTokenVerifier ();
398413 $ sessionCookieVerifier = $ this ->createSessionCookieVerifier ();
@@ -413,7 +428,11 @@ public function createDatabase(): Contract\Database
413428
414429 return new Database (
415430 GuzzleUtils::uriFor ($ databaseUrl ),
416- new Database \ApiClient ($ http , $ resourceUrlBuilder ),
431+ new Database \ApiClient (
432+ $ http ,
433+ $ resourceUrlBuilder ,
434+ new DatabaseApiExceptionConverter ($ this ->errorResponseParser ),
435+ ),
417436 );
418437 }
419438
@@ -423,7 +442,13 @@ public function createRemoteConfig(): Contract\RemoteConfig
423442 'base_uri ' => "https://firebaseremoteconfig.googleapis.com/v1/projects/ {$ this ->getProjectId ()}/remoteConfig " ,
424443 ]);
425444
426- return new RemoteConfig (new RemoteConfig \ApiClient ($ this ->getProjectId (), $ http ));
445+ return new RemoteConfig (
446+ new RemoteConfig \ApiClient (
447+ $ this ->getProjectId (),
448+ $ http ,
449+ new RemoteConfigApiExceptionConverter ($ this ->errorResponseParser ),
450+ ),
451+ );
427452 }
428453
429454 public function createMessaging (): Contract \Messaging
0 commit comments