Skip to content

Commit 68ebbbc

Browse files
committed
fix(httploader): error handling for dail tcp
1 parent 0023ee9 commit 68ebbbc

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

imagor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"time"
2020
)
2121

22-
const Version = "1.2.1"
22+
const Version = "1.2.2"
2323

2424
// Loader image loader interface
2525
type Loader interface {

loader/httploader/httploader.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,11 @@ func (h *HTTPLoader) Get(r *http.Request, image string) (*imagor.Blob, error) {
112112
return imagor.NewBlob(func() (io.ReadCloser, int64, error) {
113113
resp, err := client.Do(req)
114114
if err != nil {
115-
if strings.Contains(err.Error(), "no such host") {
115+
if idx := strings.Index(err.Error(), "dial tcp: "); idx > -1 {
116116
err = imagor.NewError(
117-
fmt.Sprintf("no such host: %s", image),
117+
fmt.Sprintf("%s: %s", err.Error()[idx:], image),
118118
http.StatusNotFound)
119119
}
120-
121120
return nil, 0, err
122121
}
123122
body := resp.Body

loader/httploader/httploader_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,5 +517,5 @@ func TestWithInvalidHost(t *testing.T) {
517517
assert.NoError(t, err)
518518
b, err := blob.ReadAll()
519519
assert.Empty(t, b)
520-
assert.Equal(t, "imagor: 404 no such host: https://foo/bar", err.Error())
520+
assert.Equal(t, 404, err.(imagor.Error).Code)
521521
}

0 commit comments

Comments
 (0)