Skip to content

Commit

Permalink
Dashboard - avoid writing body on NoContent code (#2185)
Browse files Browse the repository at this point in the history
  • Loading branch information
liranbg committed May 3, 2021
1 parent 5e1f6c9 commit c231c88
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions pkg/restful/resource.go
Expand Up @@ -476,14 +476,23 @@ func (ar *AbstractResource) callCustomRouteFunc(responseWriter http.ResponseWrit

if response.Resources == nil {

// write a valid, empty JSON
if _, err := responseWriter.Write([]byte("{}")); err != nil {

// should never happen
ar.Logger.ErrorWith("Response writer failed writing empty resources",
"err", err,
"routeFunc", routeFunc,
"request", request)
switch response.StatusCode {
case http.StatusNoContent:

// nothing to do
break
default:

// write a valid, empty JSON
if _, err := responseWriter.Write([]byte("{}")); err != nil {

// should never happen
ar.Logger.ErrorWith("Response writer failed writing empty resources",
"err", err,
"routeFunc", routeFunc,
"request", request)
}

}

return
Expand Down

0 comments on commit c231c88

Please sign in to comment.