File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -35,8 +35,6 @@ const (
3535)
3636
3737var (
38- // ErrNotFound is returned when the server returns a 404.
39- ErrNotFound = errors .New ("Not Found" )
4038 // ErrServerError is returned when the server returns a 500.
4139 ErrServerError = errors .New ("Internal Server Error" )
4240 // ErrMethodNotAllowed is thrown when using a unsupposrted method.
@@ -93,10 +91,19 @@ type ErrUnprocessable struct {
9391 errorMsg string
9492}
9593
94+ // ErrNotFound is returned when the controller throws a 404.
95+ type ErrNotFound struct {
96+ errorMsg string
97+ }
98+
9699func (e ErrUnprocessable ) Error () string {
97100 return fmt .Sprintf ("Unable to process your request: %s" , e .errorMsg )
98101}
99102
103+ func (e ErrNotFound ) Error () string {
104+ return e .errorMsg
105+ }
106+
100107// checkForErrors tries to match up an API error with an predefined error in the SDK.
101108func checkForErrors (res * http.Response ) error {
102109 if res .StatusCode >= 200 && res .StatusCode < 400 {
@@ -197,7 +204,10 @@ func checkForErrors(res *http.Response) error {
197204 case 403 :
198205 return ErrForbidden
199206 case 404 :
200- return ErrNotFound
207+ if string (out ) != "" {
208+ return ErrNotFound {string (out )}
209+ }
210+ return ErrNotFound {"Not Found" }
201211 case 405 :
202212 return ErrMethodNotAllowed
203213 case 409 :
Original file line number Diff line number Diff line change @@ -241,7 +241,14 @@ func TestErrors(t *testing.T) {
241241 StatusCode : 404 ,
242242 Body : readCloser ("" ),
243243 },
244- expected : ErrNotFound ,
244+ expected : ErrNotFound {"Not Found" },
245+ },
246+ {
247+ res : & http.Response {
248+ StatusCode : 404 ,
249+ Body : readCloser ("App not found" ),
250+ },
251+ expected : ErrNotFound {"App not found" },
245252 },
246253 {
247254 res : & http.Response {
You can’t perform that action at this time.
0 commit comments