@@ -99,9 +99,10 @@ class FirebaseUserImpl private constructor(
99
99
if (! response.isSuccessful) {
100
100
FirebaseAuth .getInstance(app).signOut()
101
101
source.setException(
102
- FirebaseAuthInvalidUserException (
103
- response.message(),
104
- FirebaseAuth .getInstance(app).formatErrorMessage(" deleteAccount" , request, response)
102
+ FirebaseAuth .getInstance(app).createAuthInvalidUserException(
103
+ " deleteAccount" ,
104
+ request,
105
+ response,
105
106
)
106
107
)
107
108
} else {
@@ -200,10 +201,7 @@ class FirebaseAuth constructor(val app: FirebaseApp) : InternalAuthProvider {
200
201
override fun onResponse (call : Call , response : Response ) {
201
202
if (! response.isSuccessful) {
202
203
source.setException(
203
- FirebaseAuthInvalidUserException (
204
- response.message(),
205
- formatErrorMessage(" accounts:signUp" , request, response)
206
- )
204
+ createAuthInvalidUserException(" accounts:signUp" , request, response)
207
205
)
208
206
} else {
209
207
val body = response.body()!! .use { it.string() }
@@ -235,10 +233,7 @@ class FirebaseAuth constructor(val app: FirebaseApp) : InternalAuthProvider {
235
233
override fun onResponse (call : Call , response : Response ) {
236
234
if (! response.isSuccessful) {
237
235
source.setException(
238
- FirebaseAuthInvalidUserException (
239
- response.message(),
240
- formatErrorMessage(" verifyCustomToken" , request, response)
241
- )
236
+ createAuthInvalidUserException(" verifyCustomToken" , request, response)
242
237
)
243
238
} else {
244
239
val body = response.body()!! .use { it.string() }
@@ -270,10 +265,7 @@ class FirebaseAuth constructor(val app: FirebaseApp) : InternalAuthProvider {
270
265
override fun onResponse (call : Call , response : Response ) {
271
266
if (! response.isSuccessful) {
272
267
source.setException(
273
- FirebaseAuthInvalidUserException (
274
- response.message(),
275
- formatErrorMessage(" verifyPassword" , request, response)
276
- )
268
+ createAuthInvalidUserException(" verifyPassword" , request, response)
277
269
)
278
270
} else {
279
271
val body = response.body()!! .use { it.string() }
@@ -285,10 +277,23 @@ class FirebaseAuth constructor(val app: FirebaseApp) : InternalAuthProvider {
285
277
return source.task
286
278
}
287
279
288
- internal fun formatErrorMessage (title : String , request : Request , response : Response ): String {
289
- return " $title API returned an error, " +
290
- " with url [${request.method()} ] ${request.url()} ${request.body()} -- " +
291
- " response [${response.code()} ] ${response.message()} ${response.body().use { it?.string() }} "
280
+ internal fun createAuthInvalidUserException (
281
+ action : String ,
282
+ request : Request ,
283
+ response : Response ,
284
+ ): FirebaseAuthInvalidUserException {
285
+ val body = response.body()!! .use { it.string() }
286
+ val jsonObject = jsonParser.parseToJsonElement(body).jsonObject
287
+
288
+ return FirebaseAuthInvalidUserException (
289
+ jsonObject[" error" ]?.jsonObject
290
+ ?.get(" message" )?.jsonPrimitive
291
+ ?.contentOrNull
292
+ ? : " UNKNOWN_ERROR" ,
293
+ " $action API returned an error, " +
294
+ " with url [${request.method()} ] ${request.url()} ${request.body()} -- " +
295
+ " response [${response.code()} ] ${response.message()} $body "
296
+ )
292
297
}
293
298
294
299
fun signOut () {
0 commit comments