Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Z-Bolt/OctoScreen.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffB42 <10328858+JeffB42@users.noreply.github.com>2021-04-18 01:06:29 +0300
committerJeffB42 <10328858+JeffB42@users.noreply.github.com>2021-04-18 01:06:29 +0300
commitd73073e600ec87a9e7191864e574adf7b91eba99 (patch)
tree2ebae6965c06b019d1bcc7041ca35fe947e7a035
parentf042bffa9d621ee791db360a7ee9140408d39e70 (diff)
added guard against RawConfirm being nil or empty
-rwxr-xr-xoctoprintApis/system.go45
1 files changed, 12 insertions, 33 deletions
diff --git a/octoprintApis/system.go b/octoprintApis/system.go
index ef1da2f..573bcae 100755
--- a/octoprintApis/system.go
+++ b/octoprintApis/system.go
@@ -2,7 +2,7 @@ package octoprintApis
import (
"encoding/json"
- "fmt"
+ // "fmt"
"github.com/Z-Bolt/OctoScreen/logger"
"github.com/Z-Bolt/OctoScreen/octoprintApis/dataModels"
@@ -11,13 +11,6 @@ import (
const SystemCommandsApiUri = "/api/system/commands"
-
-var ExecuteErrors = StatusMapping {
- 404: "The command could not be found for source and action",
- 500: "The command didn’t define a command to execute, the command returned a non-zero return code and ignore was not true or some other internal server error occurred",
-}
-
-
// SystemCommandsRequest retrieves all configured system commands.
type SystemCommandsRequest struct{}
@@ -35,39 +28,25 @@ func (cmd *SystemCommandsRequest) Do(c *Client) (*dataModels.SystemCommandsRespo
for i := range response.Core {
commandDefinition := response.Core[i]
- err = json.Unmarshal(commandDefinition.RawConfirm, &commandDefinition.Confirm)
- if err != nil {
- logger.LogError("SystemCommandsRequest.Do()", "json.Unmarshal(Core)", err)
- commandDefinition.Confirm = ""
- return nil, err
- }
+ convertRawConfirm(commandDefinition)
}
for i := range response.Custom {
commandDefinition := response.Custom[i]
- err = json.Unmarshal(commandDefinition.RawConfirm, &commandDefinition.Confirm)
- if err != nil {
- logger.LogError("SystemCommandsRequest.Do()", "json.Unmarshal(Custom)", err)
- commandDefinition.Confirm = ""
- return nil, err
- }
+ convertRawConfirm(commandDefinition)
}
return response, err
}
-// SystemExecuteCommandRequest retrieves all configured system commands.
-type SystemExecuteCommandRequest struct {
- // Source for which to list commands.
- Source dataModels.CommandSource `json:"source"`
-
- // Action is the identifier of the command, action from its definition.
- Action string `json:"action"`
-}
+func convertRawConfirm(commandDefinition *dataModels.CommandDefinition) {
+ if commandDefinition == nil || commandDefinition.RawConfirm === nil || len(commandDefinition.RawConfirm) < 1 {
+ return
+ }
-// Do sends an API request and returns an error if any.
-func (cmd *SystemExecuteCommandRequest) Do(c *Client) error {
- uri := fmt.Sprintf("%s/%s/%s", SystemCommandsApiUri, cmd.Source, cmd.Action)
- _, err := c.doJsonRequest("POST", uri, nil, ExecuteErrors, true)
- return err
+ err = json.Unmarshal(commandDefinition.RawConfirm, &commandDefinition.Confirm)
+ if err != nil {
+ logger.LogError("SystemCommandsRequest.convertRawConfirm()", "json.Unmarshal(Custom)", err)
+ commandDefinition.Confirm = ""
+ }
}