-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve: adds better error handling (#12)
- Loading branch information
1 parent
f964c6d
commit 3ec2afb
Showing
5 changed files
with
271 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// LLMChatOpenAIError.swift | ||
// LLMChatOpenAI | ||
// | ||
// Created by Kevin Hermawan on 10/27/24. | ||
// | ||
|
||
import Foundation | ||
|
||
/// An enum that represents errors from the chat completion request. | ||
public enum LLMChatOpenAIError: LocalizedError { | ||
/// A case that represents a server-side error response. | ||
/// | ||
/// - Parameter message: The error message from the server. | ||
case serverError(String) | ||
|
||
/// A case that represents a network-related error. | ||
/// | ||
/// - Parameter error: The underlying network error. | ||
case networkError(Error) | ||
|
||
/// A case that represents an invalid server response. | ||
case badServerResponse | ||
|
||
/// A localized message that describes the error. | ||
public var errorDescription: String? { | ||
switch self { | ||
case .serverError(let error): | ||
return error | ||
case .networkError(let error): | ||
return error.localizedDescription | ||
case .badServerResponse: | ||
return "Invalid response received from server" | ||
} | ||
} | ||
} |
Oops, something went wrong.