mirror of
https://github.com/fumiama/deepinfra.git
synced 2026-06-05 00:32:46 +08:00
feat: add error status to Request
This commit is contained in:
10
api.go
10
api.go
@@ -1,7 +1,10 @@
|
||||
package deepinfra
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -29,6 +32,13 @@ func (api *API) Request(model Model) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
sb := strings.Builder{}
|
||||
sb.WriteString(resp.Status)
|
||||
sb.WriteByte(' ')
|
||||
_, _ = io.Copy(&sb, resp.Body)
|
||||
return "", errors.New(sb.String())
|
||||
}
|
||||
err = model.Parse(resp.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
Reference in New Issue
Block a user