-
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add error handling for API errors #26
Add error handling for API errors #26
Conversation
Nicely done 🤩👍 |
|
||
import Foundation | ||
|
||
enum Result<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might just use Swift.Result instead of introducing a new enum
case emptyResponse | ||
case invalidDate | ||
case configurationNotFound | ||
enum ApiError: String, Error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use LocalizedError.errorDescription
for this purpose, instead of rawValue
Pipeliner/ContentView.swift
Outdated
pipelinerService.getProjectName(baseUrl: baseUrl, projectId: projectId, token: token) { (result) in | ||
switch result { | ||
case .success(let projectName): | ||
print(projectName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep configurations update and reload here
Pipeliner/ContentView.swift
Outdated
WidgetCenter.shared.reloadAllTimelines() | ||
|
||
} else { | ||
savedBaseUrl = "not found" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
savedBaseUrl
seems to be unused anymore. Please remove it
let project = try JSONDecoder().decode(Project.self, from: data) | ||
|
||
guard let data = try? await(httpService.getData(request: request)) else { | ||
throw ApiError.emptyResponse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't drop the original error, because it might include relevant info for issue debugging.
Pipeliner/PipelinerService.swift
Outdated
do { | ||
return try gitLabService.getProjectName(baseUrl: baseUrl, projectId: projectId, token: token) | ||
let projectName = try gitLabService.getProjectName(baseUrl: baseUrl, projectId: projectId, token: token) | ||
completion(.success(projectName)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason to make this asynchronous?
…dling # Conflicts: # Pipeliner/ContentView.swift # Pipeliner/GitHub/GitHubService.swift # Pipeliner/PipelinerService.swift
Resolves #7