Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update to throw instead of returning empty list
  • Loading branch information
intitni committed Oct 6, 2024
commit d373a8c0789d847b8e39bcf84e489b263f136684
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ public enum SuggestionServiceMiddlewareContainer {

public struct DisabledLanguageSuggestionServiceMiddleware: SuggestionServiceMiddleware {
public init() {}

struct DisabledLanguageError: Error, LocalizedError {
let language: String
var errorDescription: String? {
"Suggestion service is disabled for \(language)."
}
}

public func getSuggestion(
_ request: SuggestionRequest,
Expand All @@ -55,10 +62,7 @@ public struct DisabledLanguageSuggestionServiceMiddleware: SuggestionServiceMidd
if UserDefaults.shared.value(for: \.suggestionFeatureDisabledLanguageList)
.contains(where: { $0 == language.rawValue })
{
#if DEBUG
Logger.service.info("Suggestion service is disabled for \(language).")
#endif
return []
throw DisabledLanguageError(language: language.rawValue)
}

return try await next(request)
Expand Down