homeModelsAuthStatus inspects a home models response for an authentication/error envelope. It returns the HTTP status code to surface (401 for credential issues, 502 otherwise) and true when the payload is an error response rather than model data.
(raw []byte)
| 1284 | // It returns the HTTP status code to surface (401 for credential issues, 502 otherwise) |
| 1285 | // and true when the payload is an error response rather than model data. |
| 1286 | func homeModelsAuthStatus(raw []byte) (int, bool) { |
| 1287 | errType := homeModelsErrorType(raw) |
| 1288 | if errType == "" { |
| 1289 | return 0, false |
| 1290 | } |
| 1291 | if errType == "no_credentials" || errType == "invalid_credential" { |
| 1292 | return http.StatusUnauthorized, true |
| 1293 | } |
| 1294 | return http.StatusBadGateway, true |
| 1295 | } |
| 1296 | |
| 1297 | func homeModelsErrorType(raw []byte) string { |
| 1298 | top, ok := unmarshalHomeModelsTopLevel(raw) |