Skip to content

Commit

Permalink
Improve test app errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-menu committed Jul 15, 2024
1 parent 77fb9b8 commit 1846407
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
11 changes: 9 additions & 2 deletions TestApp/Sources/App/AppModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,18 @@ extension AppModule: ModuleDelegate {
guard let error = error else { return }
if case LibraryError.cancelled = error { return }

print("Error: \(error)")
var message = ""
if let error = (error as? LocalizedError)?.errorDescription {
message += error + "\n\n"
}

var desc = ""
dump(error, to: &desc)
message += desc

presentAlert(
NSLocalizedString("error_title", comment: "Alert title for errors"),
message: error.localizedDescription,
message: message,
from: viewController
)
}
Expand Down
6 changes: 5 additions & 1 deletion TestApp/Sources/Library/LibraryError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ enum LibraryError: LocalizedError {
return String(format: NSLocalizedString("library_error_openFailed", comment: "Error message used when a low-level error occured while opening a publication"), error.localizedDescription)
case let .downloadFailed(error):
return String(format: NSLocalizedString("library_error_downloadFailed", comment: "Error message when the download of a publication failed"), error?.localizedDescription ?? "None")
default:
case .bookDeletionFailed:
return NSLocalizedString("library_error_bookDeletionFailed", comment: "Error message when the deletion of a publication failed")
case .publicationIsRestricted:
return NSLocalizedString("library_error_publicationIsRestricted", comment: "Error message when the publication is still restricted")
case .cancelled:
return nil
}
}
Expand Down
4 changes: 4 additions & 0 deletions TestApp/Sources/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
"library_error_openFailed" = "Error while opening this publication: %@";
/* Error message when the download of a publication failed */
"library_error_downloadFailed" = "Download failed: %@";
/* Error message when the deletion of a publication failed */
"library_error_bookDeletionFailed" = "Failed to delete the publication";
/* Error message when the publication is still restricted. */
"library_error_publicationIsRestricted" = "You are not allowed to open this publication";

/* Accessibility label for the library collection view */
"library_a11y_label" = "Library";
Expand Down

0 comments on commit 1846407

Please sign in to comment.