Skip to content

Commit 2287a47

Browse files
committed
updated error handling
1 parent 1bf4994 commit 2287a47

File tree

2 files changed

+2
-13
lines changed

2 files changed

+2
-13
lines changed

openai-async-image-swiftui-example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

openai-async-image-swiftui-example/ContentView.swift

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct ContentView: View {
2222
image
2323
.resizable()
2424
.scaledToFill()
25-
case .loadError(let error) : Text(handleError(error))
25+
case .loadError(let error) : Text(error.localizedDescription)
2626
case .loading : ProgressView()
2727
}
2828
}
@@ -71,14 +71,3 @@ fileprivate struct RoundedTextFieldStyle: TextFieldStyle {
7171
}
7272
}
7373

74-
// Example function to handle the error
75-
// TODO: encapsulate it in the component
76-
fileprivate func handleError(_ error: Error) -> String {
77-
if case let Http.Errors.status(_, _, data) = error {
78-
if let responseData = data, let responseString = String(data: responseData, encoding: .utf8) {
79-
return responseString
80-
}
81-
}
82-
83-
return error.localizedDescription
84-
}

0 commit comments

Comments
 (0)