From 01ab4c13a26c0fbc59d6f5b446c7f1e6868a24af Mon Sep 17 00:00:00 2001 From: Vegard Stikbakke Date: Sat, 12 Feb 2022 12:54:33 +0100 Subject: [PATCH] Fix url request type --- cmd/lambda/main.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/lambda/main.go b/cmd/lambda/main.go index 20e6996..4a26c25 100644 --- a/cmd/lambda/main.go +++ b/cmd/lambda/main.go @@ -265,13 +265,16 @@ func getFile(decodedBodyBytes []byte, contentTypeHeader string) (*extract.File, if err != nil { return nil, fmt.Errorf("failed to read response from url fetch: %w", err) } + if len(bs) == 0 { + return nil, fmt.Errorf("empty response from url") + } if strings.Contains(u, ".pdf") { return extract.NewPDF(bs), nil } if strings.Contains(u, ".jpg") || strings.Contains(u, ".jpeg") { return extract.NewJPG(bs), nil } - return &extract.File{Bytes: bs, ContentType: extract.PNG}, nil + return extract.NewPNG(bs), nil } if mediaType == "image/png" { return extract.NewPNG(decodedBodyBytes), nil