Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Typed error for Not Found (404) responses #163

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ func (c *Client) request(method, requestPath string, query url.Values, body []by
}

// check status code.
if resp.StatusCode >= 400 {
switch {
case resp.StatusCode == http.StatusNotFound:
return ErrNotFound{
BodyContents: bodyContents,
}
case resp.StatusCode >= 400:
return fmt.Errorf("status: %d, body: %v", resp.StatusCode, string(bodyContents))
}

Expand Down
11 changes: 11 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package gapi

import "fmt"

type ErrNotFound struct {
BodyContents []byte
}

func (e ErrNotFound) Error() string {
return fmt.Sprintf("status: 404, body: %s", e.BodyContents)
}