Skip to content

Commit 787101a

Browse files
feat: added SafeStatusCode method (#64)
1 parent 599838a commit 787101a

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

shared/response.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ func (resp *APIResponse) HttpNotFound() bool {
4747
return false
4848
}
4949

50+
// SafeStatusCode returns the HTTP status code from the embedded *http.Response.
51+
// Returns 0 if the receiver or the embedded response is nil.
52+
func (resp *APIResponse) SafeStatusCode() int {
53+
if resp != nil && resp.Response != nil {
54+
return resp.StatusCode
55+
}
56+
return 0
57+
}
58+
5059
// LogInfo - logs APIResponse values like RequestTime, Operation and StatusCode
5160
// does not print anything for nil APIResponse values
5261
func (resp *APIResponse) LogInfo() {

0 commit comments

Comments
 (0)