diff --git a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/PipelineController.groovy b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/PipelineController.groovy index 6b502d186f..c8e56facb3 100644 --- a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/PipelineController.groovy +++ b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/PipelineController.groovy @@ -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})" diff --git a/gate-web/src/main/groovy/com/opsmx/spinnaker/gate/exception/RetrofitErrorHandler.groovy b/gate-web/src/main/groovy/com/opsmx/spinnaker/gate/exception/RetrofitErrorHandler.groovy index 16db895466..3ccdf6d00e 100644 --- a/gate-web/src/main/groovy/com/opsmx/spinnaker/gate/exception/RetrofitErrorHandler.groovy +++ b/gate-web/src/main/groovy/com/opsmx/spinnaker/gate/exception/RetrofitErrorHandler.groovy @@ -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 @@ -45,12 +47,14 @@ class RetrofitErrorHandler { @ExceptionHandler([RetrofitError.class]) @ResponseBody ResponseEntity 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(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 { @@ -71,6 +75,36 @@ class RetrofitErrorHandler { return new ResponseEntity(defaultErrorResponse, HttpStatus.INTERNAL_SERVER_ERROR) } + @ExceptionHandler(PipelineController.PipelineException) + @ResponseBody + ResponseEntity> handlePipelineException(PipelineController.PipelineException ex) { + log.error("PipelineException occurred: {}", ex.message, ex) + Map 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> handleOesRequestException(OesRequestException ex) { + log.error("OesRequestException occurred: {}", ex.message, ex) + Map response = createResponseMap(ex, "OES Request Exception") + return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST) + } + + private Map createResponseMap(Exception ex, String errorMessage) { + Map 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()