Esempio n. 1
0
func (s *suite) TestWriteError(c *gc.C) {
	writeError := jsonhttp.WriteError(errorToResponse)
	for i, test := range writeErrorTests {
		c.Logf("%d: %s", i, test.err)
		rec := httptest.NewRecorder()
		writeError(rec, test.err)
		resp := parseErrorResponse(c, rec.Body.Bytes())
		c.Assert(resp, gc.DeepEquals, test.expectResp)
		c.Assert(rec.Code, gc.Equals, test.expectStatus)
	}
}
Esempio n. 2
0
}

func (e ErrorCode) ErrorCode() ErrorCode {
	return e
}

const (
	ErrBadRequest          = ErrorCode("bad request")
	ErrDischargeRequired   = ErrorCode("macaroon discharge required")
	ErrInteractionRequired = ErrorCode("interaction required")
)

var (
	handleJSON   = jsonhttp.HandleJSON(errorToResponse)
	handleErrors = jsonhttp.HandleErrors(errorToResponse)
	writeError   = jsonhttp.WriteError(errorToResponse)
)

// Error holds the type of a response from an httpbakery HTTP request,
// marshaled as JSON.
type Error struct {
	Code    ErrorCode  `json:",omitempty"`
	Message string     `json:",omitempty"`
	Info    *ErrorInfo `json:",omitempty"`
}

// ErrorInfo holds additional information provided
// by an error.
type ErrorInfo struct {
	// Macaroon may hold a macaroon that, when
	// discharged, may allow access to a service.