Skip to content

Commit

Permalink
Merge pull request #27 from safesoftware/error-invalid-backup-file
Browse files Browse the repository at this point in the history
Catch 500 errors when uploading files and improve error message.
  • Loading branch information
garnold54 authored Feb 6, 2023
2 parents 9ca48a1 + 3a31cdd commit fbb88ec
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
6 changes: 3 additions & 3 deletions cmd/deploymentparameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func newDeploymentParametersCmd() *cobra.Command {
# List a single deployment parameter
fmeserver deploymentparameters --name testParameter
# Output all repositories in json format
fmeserver repositories --json`,
# Output all deploymentparameters in json format
fmeserver deploymentparameters --json`,
Args: NoArgs,
RunE: deploymentParametersRun(&f),
}
Expand Down Expand Up @@ -102,7 +102,7 @@ func deploymentParametersRun(f *deploymentparametersFlags) func(cmd *cobra.Comma
if err := json.Unmarshal(responseData, &responseMessage); err == nil {

// if json output is requested, output the JSON to stdout before erroring
if jsonOutput {
if f.outputType == "json" {
prettyJSON, err := prettyPrintJSON(responseData)
if err == nil {
fmt.Fprintln(cmd.OutOrStdout(), prettyJSON)
Expand Down
6 changes: 5 additions & 1 deletion cmd/project_upload.go → cmd/projects_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ func projectUploadRun(f *projectUploadFlags) func(cmd *cobra.Command, args []str
if err != nil {
return err
} else if response.StatusCode != http.StatusOK {
return errors.New(response.Status)
if response.StatusCode == http.StatusInternalServerError {
return fmt.Errorf("%w: check that the file specified is a valid project file", errors.New(response.Status))
} else {
return errors.New(response.Status)
}
}

responseData, err := io.ReadAll(response.Body)
Expand Down
2 changes: 1 addition & 1 deletion cmd/projects_upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestProjectUpload(t *testing.T) {
{
name: "500 bad status code",
statusCode: http.StatusInternalServerError,
wantErrText: "500 Internal Server Error",
wantErrText: "500 Internal Server Error: check that the file specified is a valid project file",
args: []string{"projects", "upload", "--file", f.Name()},
},
{
Expand Down
8 changes: 7 additions & 1 deletion cmd/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,17 @@ func restoreRun(f *restoreFlags) func(cmd *cobra.Command, args []string) error {
if err != nil {
return err
} else if !f.resource && response.StatusCode != http.StatusOK {
return errors.New(response.Status)
if response.StatusCode == http.StatusInternalServerError {
return fmt.Errorf("%w: check that the file specified is a valid backup file", errors.New(response.Status))
} else {
return errors.New(response.Status)
}

} else if f.resource && response.StatusCode != http.StatusAccepted {
if response.StatusCode == http.StatusUnprocessableEntity {
return fmt.Errorf("%w: check that the specified shared resource and file exist", errors.New(response.Status))
}

return errors.New(response.Status)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestRestore(t *testing.T) {
{
name: "500 bad status code",
statusCode: http.StatusInternalServerError,
wantErrText: "500 Internal Server Error",
wantErrText: "500 Internal Server Error: check that the file specified is a valid backup file",
args: []string{"restore", "--file", f.Name()},
},
{
Expand Down

0 comments on commit fbb88ec

Please sign in to comment.