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

Refactoring + error handling fixes #159

Merged
merged 9 commits into from
Nov 6, 2024
21 changes: 5 additions & 16 deletions sdk/authentication/token_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,14 @@ func GetToken(credentials settings.AuthenticationSettings, httpSettings *setting
if err != nil {
return localVarReturnValue, localVarHttpResponse, err
}
if localVarHttpResponse.StatusCode < 300 {
err = decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"))
if err == nil {
return localVarReturnValue, localVarHttpResponse, err
}
}
if localVarHttpResponse.StatusCode >= 300 {

if localVarHttpResponse.StatusCode < 200 || localVarHttpResponse.StatusCode >= 300 {
newErr := fmt.Errorf(string(localVarBody))
if localVarHttpResponse.StatusCode == 200 {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

more dead code

var v model.Task
err = decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"))
if err != nil {
return localVarReturnValue, localVarHttpResponse, newErr
}
return localVarReturnValue, localVarHttpResponse, newErr
}
return localVarReturnValue, localVarHttpResponse, newErr
} else {
err = decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"))
}
return localVarReturnValue, localVarHttpResponse, nil
return localVarReturnValue, localVarHttpResponse, err
}

func prepareRequest(
Expand Down
167 changes: 42 additions & 125 deletions sdk/client/api_application_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,14 @@ func (a *ApplicationResourceApiService) AddRoleToApplicationUser(ctx context.Con
return returnValue, httpResponse, err
}

if httpResponse.StatusCode < 300 {
// If we succeed, return the data, otherwise pass on to decode error.
if isSuccessfulStatus(httpResponse.StatusCode) {
err = a.decode(&returnValue, responseBody, httpResponse.Header.Get("Content-Type"))
if err == nil {
return returnValue, httpResponse, err
}
}

if httpResponse.StatusCode >= 300 {
} else {
newErr := NewGenericSwaggerError(responseBody, httpResponse.Status, nil, httpResponse.StatusCode)
return returnValue, httpResponse, newErr
}

return returnValue, httpResponse, nil
return returnValue, httpResponse, err
}

/*
Expand Down Expand Up @@ -154,20 +148,14 @@ func (a *ApplicationResourceApiService) CreateAccessKey(ctx context.Context, id
return nil, httpResponse, err
}

if httpResponse.StatusCode < 300 {
// If we succeed, return the data, otherwise pass on to decode error.
if isSuccessfulStatus(httpResponse.StatusCode) {
err = a.decode(&returnValue, responseBody, httpResponse.Header.Get("Content-Type"))
if err == nil {
return &returnValue, httpResponse, err
}
}

if httpResponse.StatusCode >= 300 {
} else {
newErr := NewGenericSwaggerError(responseBody, httpResponse.Status, nil, httpResponse.StatusCode)
return nil, httpResponse, newErr
}

return nil, httpResponse, nil
return &returnValue, httpResponse, err
}

/*
Expand Down Expand Up @@ -227,20 +215,14 @@ func (a *ApplicationResourceApiService) CreateApplication(ctx context.Context, b
return nil, httpResponse, err
}

if httpResponse.StatusCode < 300 {
// If we succeed, return the data, otherwise pass on to decode error.
if isSuccessfulStatus(httpResponse.StatusCode) {
err = a.decode(&returnValue, responseBody, httpResponse.Header.Get("Content-Type"))
if err == nil {
return &returnValue, httpResponse, err
}
}

if httpResponse.StatusCode >= 300 {
} else {
newErr := NewGenericSwaggerError(responseBody, httpResponse.Status, nil, httpResponse.StatusCode)
return nil, httpResponse, newErr
}

return nil, httpResponse, nil
return &returnValue, httpResponse, err
}

/*
Expand Down Expand Up @@ -301,20 +283,13 @@ func (a *ApplicationResourceApiService) DeleteAccessKey(ctx context.Context, app
return httpResponse, err
}

if httpResponse.StatusCode < 300 {
// If we succeed, return the data, otherwise pass on to decode error.
if isSuccessfulStatus(httpResponse.StatusCode) {
err = a.decode(&returnValue, responseBody, httpResponse.Header.Get("Content-Type"))
if err == nil {
return httpResponse, err
}
}

if httpResponse.StatusCode >= 300 {
newErr := NewGenericSwaggerError(responseBody, httpResponse.Status, nil, httpResponse.StatusCode)
return httpResponse, newErr
} else {
return httpResponse, NewGenericSwaggerError(responseBody, httpResponse.Status, nil, httpResponse.StatusCode)
}

return httpResponse, nil
return httpResponse, err
}

/*
Expand Down Expand Up @@ -373,20 +348,14 @@ func (a *ApplicationResourceApiService) DeleteApplication(ctx context.Context, i
return returnValue, httpResponse, err
}

if httpResponse.StatusCode < 300 {
// If we succeed, return the data, otherwise pass on to decode error.
if isSuccessfulStatus(httpResponse.StatusCode) {
err = a.decode(&returnValue, responseBody, httpResponse.Header.Get("Content-Type"))
if err == nil {
return returnValue, httpResponse, err
}
}

if httpResponse.StatusCode >= 300 {
} else {
newErr := NewGenericSwaggerError(responseBody, httpResponse.Status, nil, httpResponse.StatusCode)
return returnValue, httpResponse, newErr
}

return returnValue, httpResponse, nil
return returnValue, httpResponse, err
}

/*
Expand Down Expand Up @@ -446,9 +415,8 @@ func (a *ApplicationResourceApiService) DeleteTagForApplication(ctx context.Cont
return httpResponse, err
}

if httpResponse.StatusCode >= 300 {
newErr := NewGenericSwaggerError(responseBody, httpResponse.Status, nil, httpResponse.StatusCode)
return httpResponse, newErr
if !isSuccessfulStatus(httpResponse.StatusCode) {
return httpResponse, NewGenericSwaggerError(responseBody, httpResponse.Status, nil, httpResponse.StatusCode)
}

return httpResponse, nil
Expand Down Expand Up @@ -510,20 +478,14 @@ func (a *ApplicationResourceApiService) GetAccessKeys(ctx context.Context, id st
return returnValue, httpResponse, err
}

if httpResponse.StatusCode < 300 {
// If we succeed, return the data, otherwise pass on to decode error.
if isSuccessfulStatus(httpResponse.StatusCode) {
err = a.decode(&returnValue, responseBody, httpResponse.Header.Get("Content-Type"))
if err == nil {
return returnValue, httpResponse, err
}
}

if httpResponse.StatusCode >= 300 {
} else {
newErr := NewGenericSwaggerError(responseBody, httpResponse.Status, nil, httpResponse.StatusCode)
return returnValue, httpResponse, newErr
}

return returnValue, httpResponse, nil
return returnValue, httpResponse, err
}

/*
Expand Down Expand Up @@ -582,20 +544,14 @@ func (a *ApplicationResourceApiService) GetAppByAccessKeyId(ctx context.Context,
return returnValue, httpResponse, err
}

if httpResponse.StatusCode < 300 {
// If we succeed, return the data, otherwise pass on to decode error.
if isSuccessfulStatus(httpResponse.StatusCode) {
err = a.decode(&returnValue, responseBody, httpResponse.Header.Get("Content-Type"))
if err == nil {
return returnValue, httpResponse, err
}
}

if httpResponse.StatusCode >= 300 {
} else {
newErr := NewGenericSwaggerError(responseBody, httpResponse.Status, nil, httpResponse.StatusCode)
return returnValue, httpResponse, newErr
}

return returnValue, httpResponse, nil
return returnValue, httpResponse, err
}

/*
Expand Down Expand Up @@ -654,20 +610,14 @@ func (a *ApplicationResourceApiService) GetApplication(ctx context.Context, id s
return nil, httpResponse, err
}

if httpResponse.StatusCode < 300 {
// If we succeed, return the data, otherwise pass on to decode error.
if isSuccessfulStatus(httpResponse.StatusCode) {
err = a.decode(&returnValue, responseBody, httpResponse.Header.Get("Content-Type"))
if err == nil {
return &returnValue, httpResponse, err
}
}

if httpResponse.StatusCode >= 300 {
} else {
newErr := NewGenericSwaggerError(responseBody, httpResponse.Status, nil, httpResponse.StatusCode)
return nil, httpResponse, newErr
}

return nil, httpResponse, nil
return &returnValue, httpResponse, err
}

/*
Expand Down Expand Up @@ -726,20 +676,14 @@ func (a *ApplicationResourceApiService) GetTagsForApplication(ctx context.Contex
return returnValue, httpResponse, err
}

if httpResponse.StatusCode < 300 {
// If we succeed, return the data, otherwise pass on to decode error.
if isSuccessfulStatus(httpResponse.StatusCode) {
err = a.decode(&returnValue, responseBody, httpResponse.Header.Get("Content-Type"))
if err == nil {
return returnValue, httpResponse, err
}
}

if httpResponse.StatusCode >= 300 {
} else {
newErr := NewGenericSwaggerError(responseBody, httpResponse.Status, nil, httpResponse.StatusCode)
return returnValue, httpResponse, newErr
}

return returnValue, httpResponse, nil
return returnValue, httpResponse, err
}

/*
Expand Down Expand Up @@ -796,20 +740,14 @@ func (a *ApplicationResourceApiService) ListApplications(ctx context.Context) ([
return returnValue, httpResponse, err
}

if httpResponse.StatusCode < 300 {
// If we succeed, return the data, otherwise pass on to decode error.
if isSuccessfulStatus(httpResponse.StatusCode) {
err = a.decode(&returnValue, responseBody, httpResponse.Header.Get("Content-Type"))
if err == nil {
return returnValue, httpResponse, err
}
}

if httpResponse.StatusCode >= 300 {
} else {
newErr := NewGenericSwaggerError(responseBody, httpResponse.Status, nil, httpResponse.StatusCode)
return returnValue, httpResponse, newErr
}

return returnValue, httpResponse, nil
return returnValue, httpResponse, err
}

/*
Expand Down Expand Up @@ -869,9 +807,8 @@ func (a *ApplicationResourceApiService) PutTagForApplication(ctx context.Context
return httpResponse, err
}

if httpResponse.StatusCode >= 300 {
newErr := NewGenericSwaggerError(responseBody, httpResponse.Status, nil, httpResponse.StatusCode)
return httpResponse, newErr
if !isSuccessfulStatus(httpResponse.StatusCode) {
return httpResponse, NewGenericSwaggerError(responseBody, httpResponse.Status, nil, httpResponse.StatusCode)
}

return httpResponse, nil
Expand Down Expand Up @@ -935,20 +872,14 @@ func (a *ApplicationResourceApiService) RemoveRoleFromApplicationUser(ctx contex
return returnValue, httpResponse, err
}

if httpResponse.StatusCode < 300 {
// If we succeed, return the data, otherwise pass on to decode error.
if isSuccessfulStatus(httpResponse.StatusCode) {
err = a.decode(&returnValue, responseBody, httpResponse.Header.Get("Content-Type"))
if err == nil {
return returnValue, httpResponse, err
}
}

if httpResponse.StatusCode >= 300 {
} else {
newErr := NewGenericSwaggerError(responseBody, httpResponse.Status, nil, httpResponse.StatusCode)
return returnValue, httpResponse, newErr
}

return returnValue, httpResponse, nil
return returnValue, httpResponse, err
}

/*
Expand Down Expand Up @@ -1009,15 +940,7 @@ func (a *ApplicationResourceApiService) ToggleAccessKeyStatus(ctx context.Contex
return returnValue, httpResponse, err
}

if httpResponse.StatusCode < 300 {
// If we succeed, return the data, otherwise pass on to decode error.
err = a.decode(&returnValue, responseBody, httpResponse.Header.Get("Content-Type"))
if err == nil {
return returnValue, httpResponse, err
}
}

if httpResponse.StatusCode >= 300 {
if !isSuccessfulStatus(httpResponse.StatusCode) {
newErr := NewGenericSwaggerError(responseBody, httpResponse.Status, nil, httpResponse.StatusCode)
return returnValue, httpResponse, newErr
}
Expand Down Expand Up @@ -1084,18 +1007,12 @@ func (a *ApplicationResourceApiService) UpdateApplication(ctx context.Context, b
return nil, httpResponse, err
}

if httpResponse.StatusCode < 300 {
// If we succeed, return the data, otherwise pass on to decode error.
if isSuccessfulStatus(httpResponse.StatusCode) {
err = a.decode(&returnValue, responseBody, httpResponse.Header.Get("Content-Type"))
if err == nil {
return &returnValue, httpResponse, err
}
}

if httpResponse.StatusCode >= 300 {
} else {
newErr := NewGenericSwaggerError(responseBody, httpResponse.Status, nil, httpResponse.StatusCode)
return nil, httpResponse, newErr
}

return nil, httpResponse, nil
return &returnValue, httpResponse, err
}
Loading
Loading