Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make error responses better #156

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sdk/client/api_application_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ func (a *ApplicationResourceApiService) CreateApplication(ctx context.Context, b
}

if httpResponse.StatusCode >= 300 {
newErr := GenericSwaggerError{
body: responseBody,
newErr := GenericSwaggerErrorV2{
body: string(responseBody),
error: httpResponse.Status,
}
return nil, httpResponse, newErr
Expand Down
25 changes: 23 additions & 2 deletions sdk/client/generic_swagger_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,37 @@ type GenericSwaggerError struct {
model interface{}
}

type GenericSwaggerErrorV2 struct {
body string
error string
model interface{}
}

// Error returns non-empty string if there was an error.
func (e GenericSwaggerError) Error() string {
func (e GenericSwaggerErrorV2) Error() string {
Copy link
Contributor Author

@codehackerr codehackerr Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't need GenericSwaggerErrorV2 , just for demo. Change GenericSwaggerError if we decide in favor.

return fmt.Sprintf("error: %s, body: %s", e.error, e.body)
}

// Body returns the raw bytes of the response
func (e GenericSwaggerError) Body() []byte {
func (e GenericSwaggerErrorV2) Body() string {
return e.body
}

// Model returns the unpacked model of the error
func (e GenericSwaggerErrorV2) Model() interface{} {
return e.model
}

// Error returns non-empty string if there was an error.
func (e GenericSwaggerError) Error() string {
return fmt.Sprintf("error: %s, body: %s", e.error, e.body)
}

// Body returns the raw bytes of the response
func (e GenericSwaggerError) Body() string {
return string(e.body)
}

// Model returns the unpacked model of the error
func (e GenericSwaggerError) Model() interface{} {
return e.model
Expand Down
Loading