Skip to content

Commit

Permalink
Don't wrap server errors in an error: object.
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Promislow <[email protected]>
  • Loading branch information
ericpromislow committed Apr 6, 2022
1 parent ce88613 commit 7dec9e2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
6 changes: 3 additions & 3 deletions e2e/rdctl.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ test.describe('HTTP control interface', () => {
const { stdout, stderr, error } = await rdctl(['api', endpoint]);

expect(error).toBeUndefined();
expect(JSON.parse(stdout)).toEqual({ error: { message: '404 Not Found', documentation_url: null } });
expect(JSON.parse(stdout)).toEqual({ message: '404 Not Found', documentation_url: null });
expect(stderr).not.toContain('Usage:');
expect(stderr).toContain(`Unknown command: GET ${ endpoint }`);
});
Expand All @@ -488,7 +488,7 @@ test.describe('HTTP control interface', () => {
const { stdout, stderr, error } = await rdctl(['api', 'settings', '-X', 'PUT']);

expect(error).toBeUndefined();
expect(JSON.parse(stdout)).toEqual({ error: { message: '400 Bad Request', documentation_url: null } });
expect(JSON.parse(stdout)).toEqual({ message: '400 Bad Request', documentation_url: null });
expect(stderr).not.toContain('Usage:');
expect(stderr).toContain('no settings specified in the request');
});
Expand All @@ -498,7 +498,7 @@ test.describe('HTTP control interface', () => {
const { stdout, stderr, error } = await rdctl(['api', 'settings', '-b', JSON.stringify(newSettings)]);

expect(error).toBeUndefined();
expect(JSON.parse(stdout)).toEqual({ error: { message: '400 Bad Request', documentation_url: null } });
expect(JSON.parse(stdout)).toEqual({ message: '400 Bad Request', documentation_url: null } );
expect(stderr).not.toContain('Usage:');
expect(stderr).toMatch(/errors in attempt to update settings:\s+Invalid value for kubernetes.containerEngine: <beefalo>; must be 'containerd', 'docker', or 'moby'/);
});
Expand Down
8 changes: 3 additions & 5 deletions src/go/rdctl/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ import (
)

type APIError struct {
Error struct {
Message *string `json:"message,omitifempty"`
DocumentationUrl *string `json:"documentation_url,omitifempty"`
} `json:"error"`
Message *string `json:"message,omitifempty"`
DocumentationUrl *string `json:"documentation_url,omitifempty"`
}

var (
Expand Down Expand Up @@ -141,7 +139,7 @@ func processRequestForAPI(response *http.Response, err error) ([]byte, *APIError
errorPacket := APIError{}
pErrorPacket := &errorPacket
if response.StatusCode < 200 || response.StatusCode >= 300 {
errorPacket.Error.Message = &response.Status
errorPacket.Message = &response.Status
} else {
pErrorPacket = nil
}
Expand Down

0 comments on commit 7dec9e2

Please sign in to comment.