Browse Source

Add support for 451 status code

Fixes #306.

Change-Id: I3b42c946f8255e165c3bbd83b1566675d21fb0e8
Glenn Lewis 10 years ago
parent
commit
add6dcc234
2 changed files with 16 additions and 1 deletions
  1. +7
    -0
      github/github.go
  2. +9
    -1
      github/github_test.go

+ 7
- 0
github/github.go View File

@ -366,6 +366,13 @@ type ErrorResponse struct {
Response *http.Response // HTTP response that caused this error
Message string `json:"message"` // error message
Errors []Error `json:"errors"` // more detail on individual errors
// Block is only populated on certain types of errors such as code 451.
// See https://developer.github.com/changes/2016-03-17-the-451-status-code-is-now-supported/
// for more information.
Block *struct {
Reason string `json:"reason,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
} `json:"block,omitempty"`
}
func (r *ErrorResponse) Error() string {


+ 9
- 1
github/github_test.go View File

@ -520,7 +520,8 @@ func TestCheckResponse(t *testing.T) {
Request: &http.Request{},
StatusCode: http.StatusBadRequest,
Body: ioutil.NopCloser(strings.NewReader(`{"message":"m",
"errors": [{"resource": "r", "field": "f", "code": "c"}]}`)),
"errors": [{"resource": "r", "field": "f", "code": "c"}],
"block": {"reason": "dmca", "created_at": "2016-03-17T15:39:46Z"}}`)),
}
err := CheckResponse(res).(*ErrorResponse)
@ -532,6 +533,13 @@ func TestCheckResponse(t *testing.T) {
Response: res,
Message: "m",
Errors: []Error{{Resource: "r", Field: "f", Code: "c"}},
Block: &struct {
Reason string `json:"reason,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
}{
Reason: "dmca",
CreatedAt: &Timestamp{time.Date(2016, 3, 17, 15, 39, 46, 0, time.UTC)},
},
}
if !reflect.DeepEqual(err, want) {
t.Errorf("Error = %#v, want %#v", err, want)


Loading…
Cancel
Save