소스 검색

Doc + optim

Brendan Abolivier 6 년 전
부모
커밋
13a63682a2
로그인 계정: Brendan Abolivier <contact@brendanabolivier.com> GPG 키 ID: 8EF1500759F70623
1개의 변경된 파일11개의 추가작업 그리고 5개의 파일을 삭제
  1. 11
    5
      src/grafana/dashboards.go

+ 11
- 5
src/grafana/dashboards.go 파일 보기

@@ -139,6 +139,7 @@ func (c *Client) CreateOrUpdateDashboard(contentJSON []byte) (err error) {
139 139
 		Overwrite: true,
140 140
 	}
141 141
 
142
+	// Generate the request body's JSON
142 143
 	reqBodyJSON, err := json.Marshal(reqBody)
143 144
 	if err != nil {
144 145
 		return
@@ -146,8 +147,11 @@ func (c *Client) CreateOrUpdateDashboard(contentJSON []byte) (err error) {
146 147
 
147 148
 	var httpError *httpUnkownError
148 149
 	var isHttpUnknownError bool
150
+	// Send the request
149 151
 	respBodyJSON, err := c.request("POST", "dashboards/db", reqBodyJSON)
150 152
 	if err != nil {
153
+		// Check the error against the httpUnkownError type in order to decide
154
+		// how to process the error
151 155
 		httpError, isHttpUnknownError = err.(*httpUnkownError)
152 156
 		// We process httpUnkownError errors below, after we decoded the body
153 157
 		if !isHttpUnknownError {
@@ -155,17 +159,19 @@ func (c *Client) CreateOrUpdateDashboard(contentJSON []byte) (err error) {
155 159
 		}
156 160
 	}
157 161
 
162
+	// Decode the response body
158 163
 	var respBody dbCreateOrUpdateResponse
159 164
 	if err = json.Unmarshal(respBodyJSON, &respBody); err != nil {
160 165
 		return
161 166
 	}
162 167
 
163
-	slug, err := helpers.GetDashboardSlug(contentJSON)
164
-	if err != nil {
165
-		return
166
-	}
167
-
168 168
 	if respBody.Status != "success" && isHttpUnknownError {
169
+		// Get the dashboard's slug for logging
170
+		slug, err := helpers.GetDashboardSlug(contentJSON)
171
+		if err != nil {
172
+			return
173
+		}
174
+
169 175
 		return fmt.Errorf(
170 176
 			"Failed to update dashboard %s (%d %s): %s",
171 177
 			slug, httpError.StatusCode, respBody.Status, respBody.Message,