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

OP-7604 : Handling Exceptions #48

Merged
merged 15 commits into from
Oct 5, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import java.util.stream.Collectors
import com.netflix.spinnaker.gate.config.ServiceConfiguration
import com.netflix.spinnaker.gate.services.internal.OpsmxOesService
import com.netflix.spinnaker.security.AuthenticatedRequest
import com.netflix.spinnaker.gate.exceptions.OesRequestException

import groovy.util.logging.Slf4j
import io.swagger.annotations.ApiOperation
Expand Down Expand Up @@ -319,16 +320,24 @@ class OpsmxOesController {
else
headersMap.putAt(key,"")
}
AuthenticatedRequest.propagate {
def obj = AuthenticatedRequest.propagate {
def request = new Request.Builder()
.url(serviceConfiguration.getServiceEndpoint("opsmx").url +"/oes/accountsConfig/spinnakerX509")
.headers(Headers.of(headersMap))
.post(uploadFileOkHttp(data,files))
.build()

def response = okHttpClient.newCall(request).execute()
return response.body()?.string() ?: "Unknown reason: " + response.code()
}.call() as Object
return response
}.call() as okhttp3.Response

if (!obj.isSuccessful()) {

Choose a reason for hiding this comment

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

add log error

def error = obj.body().string();
log.error("Failed to setup the Spinnaker : {}", error)
throw new OesRequestException(error)
} else{
return obj.body()?.string() ?: "Unknown reason: " + obj.code() as Object
}
}

private Object createOrUpdateSpinnaker(MultipartFile files, String data, String version) {
Expand All @@ -340,16 +349,25 @@ class OpsmxOesController {
else
headersMap.putAt(key,"")
}
AuthenticatedRequest.propagate {
def obj = AuthenticatedRequest.propagate {
def request = new Request.Builder()
.url(serviceConfiguration.getServiceEndpoint("opsmx").url +"/oes/accountsConfig/version/spinnakerX509".replace("version", version))
.headers(Headers.of(headersMap))
.post(uploadFileOkHttp(data,files))
.build()

def response = okHttpClient.newCall(request).execute()
return response.body()?.string() ?: "Unknown reason: " + response.code()
}.call() as Object
return response
}.call() as okhttp3.Response

if (!obj.isSuccessful()) {

Choose a reason for hiding this comment

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

add log error

def error = obj.body().string();
log.error("Failed to setup the Spinnaker : {}", error)
throw new OesRequestException(error)
} else{
return obj.body()?.string() ?: "Unknown reason: " + obj.code() as Object
}

}

private String addOrUpdateCloudProverAccount(MultipartFile files, String data) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.netflix.spinnaker.gate.exceptions;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
public class OesRequestException extends RuntimeException {

public OesRequestException(String message) {
super(message);
}
}