Skip to content

Commit

Permalink
Merge pull request #162 from tidal-music/ekononenko/auth-loggable-err…
Browse files Browse the repository at this point in the history
…or-code-in-metadata

AuthLoggable: added event code in metadata
  • Loading branch information
e-kononenko authored Nov 11, 2024
2 parents 3308fa3 + 5c11367 commit 8e86cf6
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Sources/Auth/Model/AuthLoggable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ extension AuthLoggable {
static var enableLogging: Bool = false
private static let metadataErrorKey = "error"
private static let metadataReasonKey = "reason"
private static let metadataCodeKey = "code"
private static let metadataPreviousSubstatusKey = "previous_substatus"

var loggingMessage: Logger.Message {
Expand Down Expand Up @@ -80,6 +81,8 @@ extension AuthLoggable {
default:
return [:]
}

metadata[Self.metadataCodeKey] = .string(eventCode)

return metadata
}
Expand All @@ -96,4 +99,35 @@ extension AuthLoggable {
var source: String? {
"Auth"
}

private var eventCode: String {
let intCode = switch self {
case .initializeDeviceLoginNetworkError:
1
case .finalizeLoginNetworkError:
2
case .finalizeDeviceLoginNetworkError:
3
case .finalizeDevicePollingLimitReached:
4
case .getCredentialsUpgradeTokenNetworkError:
5
case .getCredentialsScopeIsNotGranted:
6
case .getCredentialsClientUniqueKeyIsDifferent:
7
case .getCredentialsUpgradeTokenNoTokenInResponse:
8
case .getCredentialsRefreshTokenNetworkError:
9
case .getCredentialsRefreshTokenWithClientCredentialsNetworkError:
10
case .authLogout:
11
case .getCredentialsRefreshTokenIsNotAvailable:
12
}

return intCode.description
}
}

0 comments on commit 8e86cf6

Please sign in to comment.