| 1 | package httperrorscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/internal/httperror`/ |
| 2 | |
| 3 | import ( |
| 4 | "encoding/jsonscip-go gomod github.com/golang/go/src go1.18 `encoding/json`/" |
| 5 | "fmtscip-go gomod github.com/golang/go/src go1.18 fmt/" |
| 6 | "ioscip-go gomod github.com/golang/go/src go1.18 io/" |
| 7 | "net/httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/" |
| 8 | "stringsscip-go gomod github.com/golang/go/src go1.18 strings/" |
| 9 | ) |
| 10 | |
| 11 | type ResponseErrorscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/internal/httperror`/ResponseError# struct { |
| 12 | Methodscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/internal/httperror`/ResponseError#Method. string |
| 13 | URLscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/internal/httperror`/ResponseError#URL. string |
| 14 | Statusscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/internal/httperror`/ResponseError#Status. string |
| 15 | StatusCodescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/internal/httperror`/ResponseError#StatusCode. int |
| 16 | BodyTextscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/internal/httperror`/ResponseError#BodyText. string |
| 17 | } |
| 18 | |
| 19 | func (e ResponseErrorscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/internal/httperror`/ResponseError#) Errorscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/internal/httperror`/ResponseError#Error().() string { |
| 20 | return fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.18 fmt/Sprintf().("HTTP error:\n%s %s\n%s\n%s", e.Methodscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/internal/httperror`/ResponseError#Method., e.URLscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/internal/httperror`/ResponseError#URL., e.Statusscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/internal/httperror`/ResponseError#Status., e.BodyTextscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/internal/httperror`/ResponseError#BodyText.) |
| 21 | } |
| 22 | |
| 23 | func (e ResponseErrorscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/internal/httperror`/ResponseError#) Temporaryscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/internal/httperror`/ResponseError#Temporary().() bool { |
| 24 | return statusIsTemporaryscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/internal/httperror`/statusIsTemporary().(e.StatusCodescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/internal/httperror`/ResponseError#StatusCode.) |
| 25 | } |
| 26 | |
| 27 | func FromResponsescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/internal/httperror`/FromResponse().(resp *httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/.Responsescip-go gomod github.com/golang/go/src go1.18 `net/http`/Response#) error { |
| 28 | defer resp.Bodyscip-go gomod github.com/golang/go/src go1.18 `net/http`/Response#Body..Closescip-go gomod github.com/golang/go/src go1.18 io/Closer#Close().() |
| 29 | blob, err := ioscip-go gomod github.com/golang/go/src go1.18 io/.ReadAllscip-go gomod github.com/golang/go/src go1.18 io/ReadAll().(ioscip-go gomod github.com/golang/go/src go1.18 io/.LimitReaderscip-go gomod github.com/golang/go/src go1.18 io/LimitReader().(resp.Bodyscip-go gomod github.com/golang/go/src go1.18 `net/http`/Response#Body., 100000)) |
| 30 | if err != nil { |
| 31 | return err |
| 32 | } |
| 33 | if stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Containsscip-go gomod github.com/golang/go/src go1.18 strings/Contains().(resp.Headerscip-go gomod github.com/golang/go/src go1.18 `net/http`/Response#Header..Getscip-go gomod github.com/golang/go/src go1.18 `net/http`/Header#Get().("Content-Type"), "problem+json") { |
| 34 | var p Problemscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/internal/httperror`/Problem# |
| 35 | if err := jsonscip-go gomod github.com/golang/go/src go1.18 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.18 `encoding/json`/Unmarshal().(blob, &p); err == nil { |
| 36 | if p.Statusscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/internal/httperror`/Problem#Status. == 0 { |
| 37 | p.Statusscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/internal/httperror`/Problem#Status. = resp.StatusCodescip-go gomod github.com/golang/go/src go1.18 `net/http`/Response#StatusCode. |
| 38 | } |
| 39 | return p |
| 40 | } |
| 41 | } |
| 42 | return ResponseErrorscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/internal/httperror`/ResponseError#{ |
| 43 | Methodscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/internal/httperror`/ResponseError#Method.: resp.Requestscip-go gomod github.com/golang/go/src go1.18 `net/http`/Response#Request..Methodscip-go gomod github.com/golang/go/src go1.18 `net/http`/Request#Method., |
| 44 | URLscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/internal/httperror`/ResponseError#URL.: resp.Requestscip-go gomod github.com/golang/go/src go1.18 `net/http`/Response#Request..URLscip-go gomod github.com/golang/go/src go1.18 `net/http`/Request#URL..Stringscip-go gomod github.com/golang/go/src go1.18 `net/url`/URL#String().(), |
| 45 | Statusscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/internal/httperror`/ResponseError#Status.: resp.Statusscip-go gomod github.com/golang/go/src go1.18 `net/http`/Response#Status., |
| 46 | StatusCodescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/internal/httperror`/ResponseError#StatusCode.: resp.StatusCodescip-go gomod github.com/golang/go/src go1.18 `net/http`/Response#StatusCode., |
| 47 | BodyTextscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/internal/httperror`/ResponseError#BodyText.: string(blob), |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | func statusIsTemporaryscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/internal/httperror`/statusIsTemporary().(code int) bool { |
| 52 | switch code { |
| 53 | case httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/.StatusGatewayTimeoutscip-go gomod github.com/golang/go/src go1.18 `net/http`/StatusGatewayTimeout., |
| 54 | httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/.StatusBadGatewayscip-go gomod github.com/golang/go/src go1.18 `net/http`/StatusBadGateway., |
| 55 | httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/.StatusServiceUnavailablescip-go gomod github.com/golang/go/src go1.18 `net/http`/StatusServiceUnavailable., |
| 56 | httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/.StatusInsufficientStoragescip-go gomod github.com/golang/go/src go1.18 `net/http`/StatusInsufficientStorage., |
| 57 | httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/.StatusInternalServerErrorscip-go gomod github.com/golang/go/src go1.18 `net/http`/StatusInternalServerError.: |
| 58 | return true |
| 59 | default: |
| 60 | return false |
| 61 | } |
| 62 | } |