-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy patherrors.go
44 lines (36 loc) · 1.02 KB
/
errors.go
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
41
42
43
44
package mistral
import (
"fmt"
)
// MistralError is the base error type for all Mistral errors.
type MistralError struct {
Message string
}
func (e *MistralError) Error() string {
return e.Message
}
// MistralAPIError is returned when the API responds with an error message.
type MistralAPIError struct {
MistralError
HTTPStatus int
Headers map[string][]string
}
func NewMistralAPIError(message string, httpStatus int, headers map[string][]string) *MistralAPIError {
return &MistralAPIError{
MistralError: MistralError{Message: message},
HTTPStatus: httpStatus,
Headers: headers,
}
}
func (e *MistralAPIError) Error() string {
return fmt.Sprintf("%s (HTTP status: %d)", e.Message, e.HTTPStatus)
}
// MistralConnectionError is returned when the SDK cannot reach the API server for any reason.
type MistralConnectionError struct {
MistralError
}
func NewMistralConnectionError(message string) *MistralConnectionError {
return &MistralConnectionError{
MistralError: MistralError{Message: message},
}
}