diff --git a/github/github.go b/github/github.go index 2c7575d..2321ee7 100644 --- a/github/github.go +++ b/github/github.go @@ -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 { diff --git a/github/github_test.go b/github/github_test.go index 2ffd7d1..00b8315 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -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)