File tree Expand file tree Collapse file tree 2 files changed +57
-1
lines changed Expand file tree Collapse file tree 2 files changed +57
-1
lines changed Original file line number Diff line number Diff line change @@ -329,7 +329,7 @@ func ErrorTypeFromHTTPStatus(status int) string {
329329}
330330
331331func IsError (status int ) bool {
332- return status / 200 != 0
332+ return status < 200 || status >= 300
333333}
334334
335335func IsServerError (status int ) bool {
Original file line number Diff line number Diff line change @@ -280,3 +280,59 @@ func TestErrorTypeFromHTTPStatus(t *testing.T) {
280280 })
281281 }
282282}
283+
284+ func TestIsError (t * testing.T ) {
285+ tests := []struct {
286+ name string
287+ status int
288+ expectedResult bool
289+ }{
290+ {
291+ name : "200 OK" ,
292+ status : 200 ,
293+ expectedResult : false ,
294+ },
295+ {
296+ name : "201 Created" ,
297+ status : 201 ,
298+ expectedResult : false ,
299+ },
300+ {
301+ name : "400 Bad Request" ,
302+ status : 400 ,
303+ expectedResult : true ,
304+ },
305+ {
306+ name : "404 Not Found" ,
307+ status : 404 ,
308+ expectedResult : true ,
309+ },
310+ {
311+ name : "429 Too Many Requests" ,
312+ status : 429 ,
313+ expectedResult : true ,
314+ },
315+ {
316+ name : "500 Internal Server Error" ,
317+ status : 500 ,
318+ expectedResult : true ,
319+ },
320+ {
321+ name : "503 Service Unavailable" ,
322+ status : 503 ,
323+ expectedResult : true ,
324+ },
325+ {
326+ name : "600 Unknown" ,
327+ status : 600 ,
328+ expectedResult : true ,
329+ },
330+ }
331+
332+ for _ , tt := range tests {
333+ t .Run (tt .name , func (t * testing.T ) {
334+ result := util .IsError (tt .status )
335+ assert .Equal (t , tt .expectedResult , result )
336+ })
337+ }
338+ }
You can’t perform that action at this time.
0 commit comments