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-22790: Bugfix for return the exception messages implemented the ExceptionHandler for OesRequestException and PipelineException #487

Merged
merged 2 commits into from
Oct 17, 2024
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 @@ -116,6 +116,8 @@ class PipelineController {
String resultStatus = result.get("status")

if (!"SUCCEEDED".equalsIgnoreCase(resultStatus)) {
log.debug("Pipeline save operation failed. Result: {}", result)

String exception = result.variables.find { it.key == "exception" }?.value?.details?.errors?.getAt(0)
throw new PipelineException(
exception ?: "Pipeline save operation did not succeed: ${result.get("id", "unknown task id")} (status: ${resultStatus})"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import com.netflix.spinnaker.gate.controllers.OpsmxDashboardController
import com.netflix.spinnaker.gate.controllers.OpsmxOesController
import com.netflix.spinnaker.gate.controllers.OpsmxPlatformController
import com.netflix.spinnaker.gate.controllers.OpsmxVisibilityController
import com.netflix.spinnaker.gate.controllers.PipelineController
import com.netflix.spinnaker.gate.exceptions.OesRequestException
import com.opsmx.spinnaker.gate.controllers.OpsmxAuditClientServiceController
import com.opsmx.spinnaker.gate.controllers.OpsmxAuditServiceController
import com.opsmx.spinnaker.gate.controllers.OpsmxSaporPolicyController
Expand All @@ -45,12 +47,14 @@ class RetrofitErrorHandler {
@ExceptionHandler([RetrofitError.class])
@ResponseBody ResponseEntity<Object> handleRetrofitError(RetrofitError retrofitError){
if (retrofitError!=null){
log.warn("Exception occurred in OES downstream services : {}", retrofitError.getMessage())
log.warn("Exception occurred in OES downstream services : {}", retrofitError.getBody())
if (retrofitError.getKind() == RetrofitError.Kind.NETWORK){
log.warn("Retrofit Exception occurred of kind Network : {}", retrofitError.getBody())
ErrorResponseModel networkErrorResponse = populateNetworkErrorResponse(retrofitError)
return new ResponseEntity<Object>(networkErrorResponse, HttpStatus.INTERNAL_SERVER_ERROR)
}
if (retrofitError.getResponse()!=null && retrofitError.getResponse().getStatus() > 0){
log.warn("Exception occurred in : {}", retrofitError.getBody())
if (retrofitError.getResponse().getBody() !=null){
InputStream inputStream = null
try {
Expand All @@ -71,6 +75,36 @@ class RetrofitErrorHandler {
return new ResponseEntity<Object>(defaultErrorResponse, HttpStatus.INTERNAL_SERVER_ERROR)
}

@ExceptionHandler(PipelineController.PipelineException)
@ResponseBody
ResponseEntity<Map<String, Object>> handlePipelineException(PipelineController.PipelineException ex) {
log.error("PipelineException occurred: {}", ex.message, ex)
Map<String, Object> response = createResponseMap(ex, "Pipeline Save Error")

if (ex.additionalAttributes) {
response.put("additionalAttributes", ex.additionalAttributes)
}
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST)
}

@ExceptionHandler(OesRequestException)
@ResponseBody
ResponseEntity<Map<String, Object>> handleOesRequestException(OesRequestException ex) {
log.error("OesRequestException occurred: {}", ex.message, ex)
Map<String, Object> response = createResponseMap(ex, "OES Request Exception")
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST)
}

private Map<String, Object> createResponseMap(Exception ex, String errorMessage) {
Map<String, Object> response = [:]
response.put("error", errorMessage)
response.put("message", ex.message)
response.put("status", HttpStatus.BAD_REQUEST.value())
response.put("timestamp", System.currentTimeMillis())

return response
}


private ErrorResponseModel populateDefaultErrorResponseModel() {
ErrorResponseModel defaultErrorResponse = new ErrorResponseModel()
Expand Down
Loading