github.com/blend/go-sdk@v1.20220411.3/r2/errors.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package r2 9 10 import ( 11 "net/http" 12 "net/url" 13 14 "github.com/blend/go-sdk/ex" 15 ) 16 17 // Error Constants 18 const ( 19 // ErrRequestUnset is an error returned from options if they are called on a r2.Request that has not 20 // been created by r2.New(), and as a result the underlying request is uninitialized. 21 ErrRequestUnset ex.Class = "r2; cannot modify request, underlying request unset. please use r2.New()" 22 // ErrInvalidTransport is an error returned from options if they are called on a request that has had 23 // the transport set to something other than an *http.Transport; this precludes using http.Transport 24 // specific options like tls.Config mutators. 25 ErrInvalidTransport ex.Class = "r2; cannot modify transport, is not *http.Transport" 26 // ErrNoContentJSON is returns from sending requests when a no-content status is returned. 27 ErrNoContentJSON ex.Class = "server returned an http 204 for a request expecting json" 28 // ErrNoContentXML is returns from sending requests when a no-content status is returned. 29 ErrNoContentXML ex.Class = "server returned an http 204 for a request expecting xml" 30 // ErrInvalidMethod is an error that is returned from `r2.Request.Do()` if a method 31 // is specified on the request that violates the valid charset for HTTP methods. 32 ErrInvalidMethod ex.Class = "r2; invalid http method" 33 // ErrMismatchedPathParameters is an error that is returned from `OptParameterizedPath()` if 34 // the parameterized path string has a different number of parameters than what was passed as 35 // variadic arguments. 36 ErrMismatchedPathParameters ex.Class = "r2; route parameters provided don't match parameters needed in path" 37 ) 38 39 // ErrIsTooManyRedirects returns if the error is too many redirects. 40 func ErrIsTooManyRedirects(err error) bool { 41 if ex.Is(err, http.ErrUseLastResponse) { 42 return true 43 } 44 if typed, ok := err.(*url.Error); ok { 45 return ex.Is(typed.Err, http.ErrUseLastResponse) 46 } 47 return false 48 }