add some error handling
This commit is contained in:
parent
5859cdb097
commit
477af61528
16
main.go
16
main.go
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -43,11 +44,20 @@ func getProxyHandler(handler http.Handler) http.Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
func (t Transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||||
reqDump, _ := httputil.DumpRequest(req, true)
|
reqDump, err := httputil.DumpRequest(req, true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
res, err := t.RoundTripper.RoundTrip(req)
|
res, err := t.RoundTripper.RoundTrip(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New(err.Error() + ": " + req.URL.String())
|
||||||
|
}
|
||||||
|
|
||||||
resDump, _ := DumpResponse(res)
|
resDump, err := DumpResponse(res)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
capture := Capture{
|
capture := Capture{
|
||||||
"url": req.URL.Path,
|
"url": req.URL.Path,
|
||||||
|
@ -59,7 +69,7 @@ func (t Transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||||
|
|
||||||
save(capture)
|
save(capture)
|
||||||
|
|
||||||
return res, err
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func DumpResponse(res *http.Response) ([]byte, error) {
|
func DumpResponse(res *http.Response) ([]byte, error) {
|
||||||
|
|
Loading…
Reference in a new issue