Skip to content
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

Redact user token from error toast #1471

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Mlem/App/Models/ErrorDetails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,17 @@ struct ErrorDetails: Hashable {
}

var errorText: String {
var output: String
if let error = error as? ApiClientError {
return error.description
output = error.description
} else {
output = error?.localizedDescription ?? ""
}
return error?.localizedDescription ?? ""
for account in AccountsTracker.main.userAccounts {
if let token = account.api.token {
output.replace(token, with: "TOKEN_REDACTED")
}
}
return output
}
}
8 changes: 1 addition & 7 deletions Mlem/App/Views/Shared/ErrorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,7 @@ struct ErrorView: View {
var body: some View {
VStack(spacing: 15) {
if showingFullError {
if let error = errorDetails.error {
if let error = error as? ApiClientError {
errorDetails(error.description)
} else {
errorDetails(error.localizedDescription)
}
}
errorDetails(errorDetails.errorText)
} else {
if let systemImage = errorDetails.systemImage {
Image(systemName: systemImage)
Expand Down
Loading