Skip to content

Commit f9d9fa9

Browse files
andrewjl-muxcjpillsbury
authored andcommitted
Display a more specific error message when the direct upload POST request fails (#32)
1 parent 55840de commit f9d9fa9

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

Example/SwiftUploadSDKExample/SwiftUploadSDKExample/Model/UploadCreationModel.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import MuxUploadSDK
1111

1212
class UploadCreationModel : ObservableObject {
1313

14-
struct PickerError: Error {
14+
struct PickerError: Error, Equatable {
1515

1616
static var unexpectedFormat: PickerError {
1717
PickerError(localizedDescription: "Unexpected video file format")
@@ -24,6 +24,10 @@ class UploadCreationModel : ObservableObject {
2424
static var createUploadFailed: PickerError {
2525
PickerError(localizedDescription: "Upload could not be created")
2626
}
27+
28+
static var assetExportSessionFailed: PickerError {
29+
PickerError(localizedDescription: "Upload could not be exported")
30+
}
2731

2832
var localizedDescription: String
2933

@@ -71,7 +75,7 @@ class UploadCreationModel : ObservableObject {
7175

7276
guard let assetIdentitfier = pickerResult.assetIdentifier else {
7377
NSLog("!! No Asset ID for chosen asset")
74-
exportState = .failure(nil)
78+
exportState = .failure(UploadCreationModel.PickerError.assetExportSessionFailed)
7579
return
7680
}
7781
let options = PHFetchOptions()
@@ -93,7 +97,7 @@ class UploadCreationModel : ObservableObject {
9397
DispatchQueue.main.async {
9498
guard let exportSession = exportSession else {
9599
self.logger.error("!! No Export session")
96-
self.exportState = .failure(nil)
100+
self.exportState = .failure(UploadCreationModel.PickerError.assetExportSessionFailed)
97101
return
98102
}
99103
self.exportToOutFile(session: exportSession, outFile: tempFile)
@@ -207,7 +211,7 @@ struct PreparedUpload {
207211
}
208212

209213
enum ExportState {
210-
case not_started, preparing, failure(UploadCreationModel.PickerError?), ready(PreparedUpload)
214+
case not_started, preparing, failure(UploadCreationModel.PickerError), ready(PreparedUpload)
211215
}
212216

213217
enum PhotosAuthState {

Example/SwiftUploadSDKExample/SwiftUploadSDKExample/Screens/CreateUploadView.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ fileprivate struct ErrorView: View {
5757
.foregroundColor(.red)
5858
Spacer()
5959
.frame(maxHeight: 12)
60-
Text("Couln't prepare the video for upload. Please try another video")
60+
61+
Text(message)
6162
.foregroundColor(White)
6263
.multilineTextAlignment(.center)
6364
.font(.system(size: 12))
@@ -80,9 +81,22 @@ fileprivate struct ErrorView: View {
8081
}
8182

8283
let error: Error?
84+
85+
let message: String
8386

8487
init(error: Error? = nil) {
8588
self.error = error
89+
self.message = "Couldn't prepare the video for upload. Please try another video."
90+
}
91+
92+
init(error: UploadCreationModel.PickerError) {
93+
self.error = error
94+
95+
if error == UploadCreationModel.PickerError.createUploadFailed {
96+
self.message = "Couldn't create direct upload. Check your access token and network connectivity."
97+
} else {
98+
self.message = "Couldn't prepare the video for upload. Please try another video."
99+
}
86100
}
87101
}
88102

0 commit comments

Comments
 (0)