Skip to content
This repository has been archived by the owner on Sep 26, 2022. It is now read-only.

Commit

Permalink
fix(ios): Add missing request error handling (#224)
Browse files Browse the repository at this point in the history
* fix: Fixed missing request plugin call rejection
* refactor: Adjusted error messages to provide better information
  • Loading branch information
mrahn24 committed Feb 28, 2022
1 parent 3aca516 commit 4d86ce4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions ios/Plugin/HttpRequestHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class HttpRequestHandler {
} catch {
// Explicitly reject if the http request body was not set successfully,
// so as to not send a known malformed request, and to provide the developer with additional context.
call.reject("Error", "REQUEST", error, [:])
call.reject(error.localizedDescription, "http request", error, [:])
return
}
}
Expand All @@ -189,6 +189,8 @@ class HttpRequestHandler {
let task = urlSession.dataTask(with: urlRequest) { (data, response, error) in
urlSession.invalidateAndCancel();
if error != nil {
CAPLog.print("Error on request", String(describing: data), String(describing: response), String(describing: error))
call.reject(error!.localizedDescription, "http request", error, [:])
return
}

Expand Down Expand Up @@ -236,7 +238,7 @@ class HttpRequestHandler {
let task = URLSession.shared.uploadTask(with: urlRequest, from: form) { (data, response, error) in
if error != nil {
CAPLog.print("Error on upload file", String(describing: data), String(describing: response), String(describing: error))
call.reject("Error", "UPLOAD", error, [:])
call.reject(error!.localizedDescription, "http upload", error, [:])
return
}
let type = ResponseType(rawValue: responseType) ?? .default
Expand Down Expand Up @@ -274,12 +276,12 @@ class HttpRequestHandler {
func handleDownload(downloadLocation: URL?, response: URLResponse?, error: Error?) {
if error != nil {
CAPLog.print("Error on download file", String(describing: downloadLocation), String(describing: response), String(describing: error))
call.reject("Error", "DOWNLOAD", error, [:])
call.reject(error!.localizedDescription, "http download", error, [:])
return
}

guard let location = downloadLocation else {
call.reject("Unable to get file after downloading")
call.reject("Unable to get file after downloading", "http download")
return
}

Expand All @@ -298,7 +300,7 @@ class HttpRequestHandler {
try fileManager.moveItem(at: location, to: dest)
call.resolve(["path": dest.absoluteString])
} catch let e {
call.reject("Unable to download file", "DOWNLOAD", e)
call.reject("Unable to download file: \(e.localizedDescription)", "http download", e)
return
}

Expand Down

0 comments on commit 4d86ce4

Please sign in to comment.