@@ -15,6 +15,10 @@ type jsonItem struct {
1515}
1616
1717type jsonResponseData struct {
18+ ForbiddenError bool `json:"forbiddenError"`
19+ NotFoundError bool `json:"notFoundError"`
20+ InternalError bool `json:"internalError"`
21+
1822 Item * jsonItem `json:"item"`
1923 SubItems []* jsonItem `json:"subItems"`
2024}
@@ -44,8 +48,11 @@ func getJsonData(data *responseData) *jsonResponseData {
4448 }
4549
4650 return & jsonResponseData {
47- Item : item ,
48- SubItems : subItems ,
51+ ForbiddenError : data .HasForbiddenError ,
52+ NotFoundError : data .HasNotFoundError ,
53+ InternalError : data .HasInternalError ,
54+ Item : item ,
55+ SubItems : subItems ,
4956 }
5057}
5158
@@ -54,13 +61,7 @@ func (h *handler) json(w http.ResponseWriter, r *http.Request, data *responseDat
5461 header .Set ("Content-Type" , "application/json; charset=utf-8" )
5562 header .Set ("Cache-Control" , "public, max-age=0" )
5663
57- if data .HasInternalError {
58- w .WriteHeader (http .StatusInternalServerError )
59- } else if data .HasNotFoundError {
60- w .WriteHeader (http .StatusNotFound )
61- } else {
62- w .WriteHeader (http .StatusOK )
63- }
64+ writeHeader (w , r , data )
6465
6566 if needResponseBody (r .Method ) {
6667 jsonData := getJsonData (data )
0 commit comments