Include status code in automatic mastodon error reports

This commit is contained in:
Shadowfacts 2023-01-03 11:31:24 -05:00
parent b17b7b7a24
commit 1d9efc7fb5
2 changed files with 7 additions and 6 deletions

View File

@ -85,7 +85,7 @@ public class Client {
}
guard response.statusCode == 200 else {
let mastodonError = try? Client.decoder.decode(MastodonError.self, from: data)
let type: ErrorType = mastodonError.flatMap { .mastodonError($0.description) } ?? .unexpectedStatus(response.statusCode)
let type: ErrorType = mastodonError.flatMap { .mastodonError(response.statusCode, $0.description) } ?? .unexpectedStatus(response.statusCode)
completion(.failure(Error(request: request, type: type)))
return
}
@ -462,8 +462,8 @@ extension Client {
return "Invalid Response"
case .invalidModel(_):
return "Invalid Model"
case .mastodonError(let error):
return "Server Error: \(error)"
case .mastodonError(let code, let error):
return "Server Error (\(code)): \(error)"
}
}
}
@ -473,6 +473,6 @@ extension Client {
case invalidRequest
case invalidResponse
case invalidModel(Swift.Error)
case mastodonError(String)
case mastodonError(Int, String)
}
}

View File

@ -57,7 +57,7 @@ extension ToastConfiguration {
}
// TODO: this is a bizarre place to do this, but code path covers basically all errors
switch error.type {
case .invalidRequest, .invalidResponse, .invalidModel(_), .mastodonError(_):
case .invalidRequest, .invalidResponse, .invalidModel(_), .mastodonError(_, _):
let event = Event(error: error)
event.message = SentryMessage(formatted: "\(title): \(error)")
event.tags = [
@ -72,8 +72,9 @@ extension ToastConfiguration {
case .invalidModel(let error):
event.tags!["error_type"] = "invalid_model"
event.tags!["underlying_error"] = String(describing: error)
case .mastodonError(let error):
case .mastodonError(let code, let error):
event.tags!["error_type"] = "mastodon_error"
event.tags!["response_code"] = "\(code)"
event.tags!["underlying_error"] = error
default:
break