Check for non-success in do

This commit is contained in:
blank X 2021-08-10 13:09:51 +07:00
parent 16658e845d
commit 3718689e02
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
1 changed files with 3 additions and 3 deletions

View File

@ -87,6 +87,9 @@ func do(req *gemini.Request, via []*gemini.Request) (*gemini.Response, *gemini.R
redirect.URL = target redirect.URL = target
return do(&redirect, via) return do(&redirect, via)
} }
if resp.Status.Class() != gemini.StatusSuccess {
return resp, req, errors.New(fmt.Sprintf("%d %s", resp.Status, resp.Meta))
}
return resp, req, err return resp, req, err
} }
@ -112,9 +115,6 @@ func main() {
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.Status.Class() != gemini.StatusSuccess {
log.Fatalf("%d %s", resp.Status, resp.Meta)
}
if resp.Meta != "text/gemini" && !strings.HasPrefix(resp.Meta, "text/gemini;") { if resp.Meta != "text/gemini" && !strings.HasPrefix(resp.Meta, "text/gemini;") {
log.Fatal("mime type is not text/gemini") log.Fatal("mime type is not text/gemini")
} }