Skip to content

Commit

Permalink
refactor(web): updating custom exception message creation
Browse files Browse the repository at this point in the history
Uses new kork methods to clean up some error handling and custom exception message creation.
  • Loading branch information
Richard Timpson authored and kirangodishala committed Sep 26, 2024
1 parent 2cc5df4 commit 2d60d0d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import com.netflix.spinnaker.gate.services.PipelineService
import com.netflix.spinnaker.gate.services.TaskService
import com.netflix.spinnaker.gate.services.internal.Front50Service
import com.netflix.spinnaker.kork.exceptions.HasAdditionalAttributes
import com.netflix.spinnaker.kork.exceptions.SpinnakerException
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerHttpException
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerRetrofitErrorHandler
import com.netflix.spinnaker.kork.web.exceptions.NotFoundException
import com.netflix.spinnaker.security.AuthenticatedRequest
Expand Down Expand Up @@ -329,19 +327,11 @@ class PipelineController {
} catch (RetrofitError e) {
// If spinnakerRetrofitErrorHandler were registered as a "real" error handler, the code here would look something like
//
// } catch (SpinnakerHttpException e) {
// throw new SpinnakerHttpException(triggerFailureMessage(application, pipelineNameOrId, e), e)
// } catch (SpinnakerException e) {
// throw new SpinnakerException(triggerFailureMessage(application, pipelineNameOrId, e), e)
// throw new e.newInstance(triggerFailureMessage(application, pipelineNameOrId, e));
// }
Throwable throwable = spinnakerRetrofitErrorHandler.handleError(e)
if (throwable instanceof SpinnakerHttpException) {
throw new SpinnakerHttpException(triggerFailureMessage(application, pipelineNameOrId, throwable), throwable)
}
if (throwable instanceof SpinnakerException) {
throw new SpinnakerException(triggerFailureMessage(application, pipelineNameOrId, throwable), throwable)
}
throw throwable
throw spinnakerRetrofitErrorHandler.handleError(e, {
exception -> triggerFailureMessage(application, pipelineNameOrId, exception) });
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,10 @@ void invokePipelineConfigFront50NetworkError() throws Exception {
.perform(invokePipelineConfigRequest())
.andDo(print())
.andExpect(status().isInternalServerError())
.andExpect(status().reason("Connection reset"))
.andExpect(
status()
.reason(
"Unable to trigger pipeline (application: my-application, pipelineId: my-pipeline-id). Error: Connection reset"))
.andExpect(header().string(REQUEST_ID.getHeader(), SUBMITTED_REQUEST_ID));

verifyFront50PipelinesRequest();
Expand All @@ -398,7 +401,8 @@ void invokePipelineConfigFront50NonJsonRespone() throws Exception {
.andExpect(
status()
.reason(
"com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'this': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')\n at [Source: (retrofit.ExceptionCatchingTypedInput$ExceptionCatchingInputStream); line: 1, column: 6]"))
"Unable to trigger pipeline (application: my-application, pipelineId: my-pipeline-id). Error: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'this': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')\n"
+ " at [Source: (retrofit.ExceptionCatchingTypedInput$ExceptionCatchingInputStream); line: 1, column: 6]"))
.andExpect(header().string(REQUEST_ID.getHeader(), SUBMITTED_REQUEST_ID));

verifyFront50PipelinesRequest();
Expand Down

0 comments on commit 2d60d0d

Please sign in to comment.