Skip to content

Commit

Permalink
fix(httploader): error handling for dail tcp
Browse files Browse the repository at this point in the history
  • Loading branch information
cshum committed Oct 18, 2022
1 parent 0023ee9 commit 68ebbbc
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion imagor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"time"
)

const Version = "1.2.1"
const Version = "1.2.2"

// Loader image loader interface
type Loader interface {
Expand Down
5 changes: 2 additions & 3 deletions loader/httploader/httploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,11 @@ func (h *HTTPLoader) Get(r *http.Request, image string) (*imagor.Blob, error) {
return imagor.NewBlob(func() (io.ReadCloser, int64, error) {
resp, err := client.Do(req)
if err != nil {
if strings.Contains(err.Error(), "no such host") {
if idx := strings.Index(err.Error(), "dial tcp: "); idx > -1 {
err = imagor.NewError(
fmt.Sprintf("no such host: %s", image),
fmt.Sprintf("%s: %s", err.Error()[idx:], image),
http.StatusNotFound)
}

return nil, 0, err
}
body := resp.Body
Expand Down
2 changes: 1 addition & 1 deletion loader/httploader/httploader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,5 +517,5 @@ func TestWithInvalidHost(t *testing.T) {
assert.NoError(t, err)
b, err := blob.ReadAll()
assert.Empty(t, b)
assert.Equal(t, "imagor: 404 no such host: https://foo/bar", err.Error())
assert.Equal(t, 404, err.(imagor.Error).Code)
}

0 comments on commit 68ebbbc

Please sign in to comment.