forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
response.go
53 lines (41 loc) · 1.07 KB
/
response.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package utils
import (
"net"
"net/http"
"github.com/Azure/go-autorest/autorest"
)
func ResponseWasNotFound(resp autorest.Response) bool {
return ResponseWasStatusCode(resp, http.StatusNotFound)
}
func ResponseWasBadRequest(resp autorest.Response) bool {
return ResponseWasStatusCode(resp, http.StatusBadRequest)
}
func ResponseWasForbidden(resp autorest.Response) bool {
return ResponseWasStatusCode(resp, http.StatusForbidden)
}
func ResponseWasConflict(resp autorest.Response) bool {
return ResponseWasStatusCode(resp, http.StatusConflict)
}
func ResponseErrorIsRetryable(err error) bool {
if arerr, ok := err.(autorest.DetailedError); ok {
err = arerr.Original
}
// nolint gocritic
switch e := err.(type) {
case net.Error:
if e.Temporary() || e.Timeout() {
return true
}
}
return false
}
func ResponseWasStatusCode(resp autorest.Response, statusCode int) bool { // nolint: unparam
if r := resp.Response; r != nil {
if r.StatusCode == statusCode {
return true
}
}
return false
}