Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
ebaa33ac
Commit
ebaa33ac
authored
Jul 20, 2023
by
Bruce MacDonald
Browse files
display gin api errors in cli
parent
6a19724d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
15 deletions
+21
-15
api/client.go
api/client.go
+4
-5
api/types.go
api/types.go
+17
-10
No files found.
api/client.go
View file @
ebaa33ac
...
@@ -27,7 +27,7 @@ func checkError(resp *http.Response, body []byte) error {
...
@@ -27,7 +27,7 @@ func checkError(resp *http.Response, body []byte) error {
err
:=
json
.
Unmarshal
(
body
,
&
apiError
)
err
:=
json
.
Unmarshal
(
body
,
&
apiError
)
if
err
!=
nil
{
if
err
!=
nil
{
// Use the full body as the message if we fail to decode a response.
// Use the full body as the message if we fail to decode a response.
apiError
.
Message
=
string
(
body
)
apiError
.
Error
Message
=
string
(
body
)
}
}
return
apiError
return
apiError
...
@@ -92,7 +92,6 @@ func (c *Client) do(ctx context.Context, method, path string, reqData, respData
...
@@ -92,7 +92,6 @@ func (c *Client) do(ctx context.Context, method, path string, reqData, respData
}
}
}
}
return
nil
return
nil
}
}
func
(
c
*
Client
)
stream
(
ctx
context
.
Context
,
method
,
path
string
,
data
any
,
fn
func
([]
byte
)
error
)
error
{
func
(
c
*
Client
)
stream
(
ctx
context
.
Context
,
method
,
path
string
,
data
any
,
fn
func
([]
byte
)
error
)
error
{
...
@@ -133,9 +132,9 @@ func (c *Client) stream(ctx context.Context, method, path string, data any, fn f
...
@@ -133,9 +132,9 @@ func (c *Client) stream(ctx context.Context, method, path string, data any, fn f
if
response
.
StatusCode
>=
400
{
if
response
.
StatusCode
>=
400
{
return
StatusError
{
return
StatusError
{
StatusCode
:
response
.
StatusCode
,
StatusCode
:
response
.
StatusCode
,
Status
:
response
.
Status
,
Status
:
response
.
Status
,
Message
:
errorResponse
.
Error
,
Error
Message
:
errorResponse
.
Error
,
}
}
}
}
...
...
api/types.go
View file @
ebaa33ac
...
@@ -8,16 +8,23 @@ import (
...
@@ -8,16 +8,23 @@ import (
)
)
type
StatusError
struct
{
type
StatusError
struct
{
StatusCode
int
StatusCode
int
Status
string
Status
string
Message
string
Error
Message
string
`json:"error"`
}
}
func
(
e
StatusError
)
Error
()
string
{
func
(
e
StatusError
)
Error
()
string
{
if
e
.
Message
!=
""
{
switch
{
return
fmt
.
Sprintf
(
"%s: %s"
,
e
.
Status
,
e
.
Message
)
case
e
.
Status
!=
""
&&
e
.
ErrorMessage
!=
""
:
return
fmt
.
Sprintf
(
"%s: %s"
,
e
.
Status
,
e
.
ErrorMessage
)
case
e
.
Status
!=
""
:
return
e
.
Status
case
e
.
ErrorMessage
!=
""
:
return
e
.
ErrorMessage
default
:
// this should not happen
return
"something went wrong, please see the ollama server logs for details"
}
}
return
e
.
Status
}
}
type
GenerateRequest
struct
{
type
GenerateRequest
struct
{
...
@@ -44,10 +51,10 @@ type PullRequest struct {
...
@@ -44,10 +51,10 @@ type PullRequest struct {
}
}
type
ProgressResponse
struct
{
type
ProgressResponse
struct
{
Status
string
`json:"status"`
Status
string
`json:"status"`
Digest
string
`json:"digest,omitempty"`
Digest
string
`json:"digest,omitempty"`
Total
int
`json:"total,omitempty"`
Total
int
`json:"total,omitempty"`
Completed
int
`json:"completed,omitempty"`
Completed
int
`json:"completed,omitempty"`
}
}
type
PushRequest
struct
{
type
PushRequest
struct
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment