Skip to content

Commit

Permalink
docs(#271): mention custom http status code
Browse files Browse the repository at this point in the history
  • Loading branch information
bbortt committed May 14, 2024
1 parent 3729f42 commit 698b94f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions simulator-docs/src/main/asciidoc/concepts.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,4 @@ include::rest-api.adoc[]
include::scenario-mapper.adoc[]
include::scenarios.adoc[]
include::intermediate-messages.adoc[]
include::simulation-errors-handling.adoc[]
47 changes: 47 additions & 0 deletions simulator-docs/src/main/asciidoc/simulation-errors-handling.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[[simulations-error-handling]]
== Simulation Errors Handling

It might be possible that unexpected errors occur during simulations.
But how would you know that this is the case, you might ask yourself?
It could as well be, that someone just **wanted** this simulation to respond with an HTTP 500 code.

That's why we've invented the custom HTTP 555 status code: Simulation failed with an Exception!

The error can be asserted from the client side, the body containing more detailed information.

[source,java]
----
class SimulatorRestIT {
/**
* Sends a request to the server, expecting it to execute a simulation. The response should indicate the unexpected
* error, returning a {@link HttpStatus#INTERNAL_SERVER_ERROR}.
*
* @see org.citrusframework.simulator.sample.scenario.ThrowScenario
*/
@CitrusTest
public void testSimulationWithUnexpectedError() {
$(http().client(simulatorClient)
.send()
.get("throw")
.message()
.accept(MediaType.APPLICATION_JSON_VALUE));
$(http().client(simulatorClient)
.receive()
.response(HttpStatus.INTERNAL_SERVER_ERROR)
.message()
.body(
// language=json
"""
{
"timestamp":"@ignore@",
"status":555,
"error":"Http Status 555",
"path":"/services/rest/simulator/throw"
}
"""
));
}
}
----

0 comments on commit 698b94f

Please sign in to comment.