error processing updated

This commit is contained in:
Pavel Dmitriev 2024-05-21 23:03:32 +03:00
parent d99e197d4b
commit 404a1a9a61
1 changed files with 21 additions and 1 deletions

20
api.go
View File

@ -26,6 +26,18 @@ func (e MlflowApiError) Error() string {
return fmt.Sprint("Request Error " + string(e.ErrorCode) + ": " + e.ErrorDesc) return fmt.Sprint("Request Error " + string(e.ErrorCode) + ": " + e.ErrorDesc)
} }
type MlflowApiErrorNotFound MlflowApiError
func (e MlflowApiErrorNotFound) Error() string {
return fmt.Sprint("Request Error 404 " + string(e.ErrorCode) + ": " + e.ErrorDesc)
}
type MlflowApiError400 MlflowApiError
func (e MlflowApiError400) Error() string {
return fmt.Sprint("Request Error 400 " + string(e.ErrorCode) + ": " + e.ErrorDesc)
}
type Timestamp int64 type Timestamp int64
func (t *Timestamp) Time() time.Time { func (t *Timestamp) Time() time.Time {
@ -67,8 +79,16 @@ func apiReadReply(resp *http.Response, err error, ref any) error {
fmt.Println("Error when parsing reply: ", err2.Error(), "\n", string(body)) fmt.Println("Error when parsing reply: ", err2.Error(), "\n", string(body))
return err2 return err2
} }
switch resp.StatusCode {
case 400:
return MlflowApiError400(err)
case 404:
return MlflowApiErrorNotFound(err)
default:
return err return err
} }
}
err = json.Unmarshal(body, &ref) err = json.Unmarshal(body, &ref)