Classify PromptKit generation errors safely
This commit is contained in:
@@ -9,3 +9,31 @@ var ErrInvalidStructuredOutput = errors.New("invalid structured output")
|
||||
// ErrLLMCapacityExceeded identifies backend admission exhaustion before model
|
||||
// generation begins.
|
||||
var ErrLLMCapacityExceeded = errors.New("LLM capacity exceeded")
|
||||
|
||||
// ErrLLMGeneration identifies a provider generation failure.
|
||||
var ErrLLMGeneration = errors.New("LLM generation failed")
|
||||
|
||||
type LLMGenerationError struct {
|
||||
status int
|
||||
diagnostic string
|
||||
}
|
||||
|
||||
func NewLLMGenerationError(status int, diagnostic string) *LLMGenerationError {
|
||||
if status < 0 {
|
||||
status = 0
|
||||
}
|
||||
return &LLMGenerationError{status: status, diagnostic: diagnostic}
|
||||
}
|
||||
func (e *LLMGenerationError) Error() string {
|
||||
if e == nil || e.diagnostic == "" {
|
||||
return ErrLLMGeneration.Error()
|
||||
}
|
||||
return e.diagnostic
|
||||
}
|
||||
func (e *LLMGenerationError) Unwrap() error { return ErrLLMGeneration }
|
||||
func (e *LLMGenerationError) StatusCode() int {
|
||||
if e == nil {
|
||||
return 0
|
||||
}
|
||||
return e.status
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user