-
Notifications
You must be signed in to change notification settings - Fork 847
Expand file tree
/
Copy pathCodebuffUsageError.swift
More file actions
40 lines (36 loc) · 1.34 KB
/
CodebuffUsageError.swift
File metadata and controls
40 lines (36 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import Foundation
public enum CodebuffUsageError: LocalizedError, Sendable, Equatable {
case missingCredentials
case unauthorized
case endpointNotFound
case serviceUnavailable(Int)
case apiError(Int)
case networkError(String)
case parseFailed(String)
public static let missingToken: CodebuffUsageError = .missingCredentials
public var errorDescription: String? {
switch self {
case .missingCredentials:
"Codebuff API token not configured. Set CODEBUFF_API_KEY or run `codebuff login` to " +
"populate ~/.config/manicode/credentials.json."
case .unauthorized:
"Unauthorized. Please sign in to Codebuff again."
case .endpointNotFound:
"Codebuff usage endpoint not found."
case let .serviceUnavailable(status):
"Codebuff API is temporarily unavailable (status \(status))."
case let .apiError(status):
"Codebuff API returned an unexpected status (\(status))."
case let .networkError(message):
"Codebuff API error: \(message)"
case let .parseFailed(message):
"Could not parse Codebuff usage: \(message)"
}
}
public var isAuthRelated: Bool {
switch self {
case .unauthorized, .missingCredentials: true
default: false
}
}
}