Skip to content

Commit 2aedc9a

Browse files
author
Tito Ciuro
committed
Fix error generation when status is .internal
- when the error received is of type `.internal`, the current code rewrites the message with `descriptionForErrorCode`. This is pretty bad because any contextual information we might have received from Firebase is destroyed. - this fix attempts to extract the message from the response payload, preserving the original value. - if message is not found, the message is set to the value returned by `descriptionForErrorCode`, as was done before.
1 parent 8066d19 commit 2aedc9a

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

FirebaseFunctions/Sources/FunctionsError.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,18 +225,18 @@ internal func FunctionsErrorForResponse(status: NSInteger,
225225
if let status = errorDetails["status"] as? String {
226226
code = FunctionsErrorCode.errorCode(forName: status)
227227

228+
if let message = errorDetails["message"] as? String {
229+
description = message
230+
} else {
231+
description = code.descriptionForErrorCode
232+
}
233+
228234
// If the code in the body is invalid, treat the whole response as malformed.
229235
guard code != .internal else {
230-
return code.generatedError(userInfo: nil)
236+
return code.generatedError(userInfo: [NSLocalizedDescriptionKey: description])
231237
}
232238
}
233-
234-
if let message = errorDetails["message"] as? String {
235-
description = message
236-
} else {
237-
description = code.descriptionForErrorCode
238-
}
239-
239+
240240
details = errorDetails["details"] as AnyObject?
241241
if let innerDetails = details {
242242
// Just ignore the details if there an error decoding them.

0 commit comments

Comments
 (0)