Skip to content

Commit

Permalink
return err instead of panic in JSON Render
Browse files Browse the repository at this point in the history
Change-Id: I3ce1afb327fea7a92a21e27649f7af87e286bf26
  • Loading branch information
Tevic committed Jan 26, 2022
1 parent 580e7da commit 7fb2501
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
5 changes: 1 addition & 4 deletions render/json.go
Expand Up @@ -54,10 +54,7 @@ var (

// Render (JSON) writes data with custom ContentType.
func (r JSON) Render(w http.ResponseWriter) (err error) {
if err = WriteJSON(w, r.Data); err != nil {
panic(err)
}
return
return WriteJSON(w, r.Data)
}

// WriteContentType (JSON) writes JSON ContentType.
Expand Down
4 changes: 2 additions & 2 deletions render/render_test.go
Expand Up @@ -39,12 +39,12 @@ func TestRenderJSON(t *testing.T) {
assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type"))
}

func TestRenderJSONPanics(t *testing.T) {
func TestRenderJSONError(t *testing.T) {
w := httptest.NewRecorder()
data := make(chan int)

// json: unsupported type: chan int
assert.Panics(t, func() { assert.NoError(t, (JSON{data}).Render(w)) })
assert.Error(t, (JSON{data}).Render(w))
}

func TestRenderIndentedJSON(t *testing.T) {
Expand Down

0 comments on commit 7fb2501

Please sign in to comment.