✨ Add options, mostly transformers
This commit is contained in:
parent
b1e4c28dfe
commit
b4b4f041d7
4 changed files with 121 additions and 11 deletions
|
|
@ -43,6 +43,10 @@ func (s *MiddlewareTestSuite) do(err ...error) {
|
|||
|
||||
func (s *MiddlewareTestSuite) doParse(err ...error) map[string]any {
|
||||
s.do(err...)
|
||||
return s.parse()
|
||||
}
|
||||
|
||||
func (s *MiddlewareTestSuite) parse() map[string]any {
|
||||
var out map[string]any
|
||||
jsonErr := json.Unmarshal(s.w.Body.Bytes(), &out)
|
||||
s.Assert().Nil(jsonErr)
|
||||
|
|
@ -98,3 +102,18 @@ func (s *MiddlewareTestSuite) TestOtherError() {
|
|||
s.Assert().Equal("Unknown Error", outMsg)
|
||||
s.Assert().Equal(http.StatusInternalServerError, s.w.Code)
|
||||
}
|
||||
|
||||
func (s *MiddlewareTestSuite) TestNoWorkingTransformer() {
|
||||
var noop Transformer = func(err error) rErrors.ResponsableError {
|
||||
return nil
|
||||
}
|
||||
err := errors.New("Foo")
|
||||
s.ctx.Error(err)
|
||||
ErrorMiddleware(WithTransformer(noop))(s.ctx)
|
||||
|
||||
out := s.parse()
|
||||
outMsg, ok := out["error"].(string)
|
||||
s.Assert().True(ok)
|
||||
s.Assert().Equal("Unknown Error", outMsg)
|
||||
s.Assert().Equal(http.StatusInternalServerError, s.w.Code)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue