@Test public void errorHandling() throws Exception { TestResponse response = createClient(Main::errorHandling) .path("/compute") .post(MediaPublisher.create(MediaType.TEXT_PLAIN, "2")); assertEquals(200, response.status().code()); assertEquals("100 / 2 = 50", response.asString().get()); response = createClient(Main::errorHandling) .path("/compute") .post(MediaPublisher.create(MediaType.TEXT_PLAIN, "0")); assertEquals(412, response.status().code()); response = createClient(Main::errorHandling) .path("/compute") .post(MediaPublisher.create(MediaType.TEXT_PLAIN, "aaa")); assertEquals(400, response.status().code()); }
public void errorHandling() { Routing routing = Routing.builder() .post("/compute", Handler.create(String.class, (req, res, str) -> { int result = 100 / Integer.parseInt(str); res.send(String.valueOf("100 / " + str + " = " + result)); })) .error(Throwable.class, (req, res, ex) -> { ex.printStackTrace(System.out); req.next(); }) .error(NumberFormatException.class, (req, res, ex) -> res.status(Http.Status.BAD_REQUEST_400).send()) .error(ArithmeticException.class, (req, res, ex) -> res.status(Http.Status.PRECONDITION_FAILED_412).send()) .build(); startServer(routing); }
Main { public void errorHandling() { Routing routing = Routing.builder() .post("/compute", Handler.create(String.class, (req, res, str) -> { int result = 100 / Integer.parseInt(str); res.send(String.valueOf("100 / " + str + " = " + result)); })) .error(Throwable.class, (req, res, ex) -> { ex.printStackTrace(System.out); req.next(); }) .error(NumberFormatException.class, (req, res, ex) -> res.status(Http.Status.BAD_REQUEST_400).send()) .error(ArithmeticException.class, (req, res, ex) -> res.status(Http.Status.PRECONDITION_FAILED_412).send()) .build(); startServer(routing); } }
Main { public void errorHandling() { Routing routing = Routing.builder() .post("/compute", Handler.create(String.class, (req, res, str) -> { int result = 100 / Integer.parseInt(str); res.send(String.valueOf("100 / " + str + " = " + result)); })) .error(Throwable.class, (req, res, ex) -> { ex.printStackTrace(System.out); req.next(); }) .error(NumberFormatException.class, (req, res, ex) -> res.status(Http.Status.BAD_REQUEST_400).send()) .error(ArithmeticException.class, (req, res, ex) -> res.status(Http.Status.PRECONDITION_FAILED_412).send()) .build(); startServer(routing); }  }
Main { public void errorHandling() { Routing routing = Routing.builder() .post("/compute", Handler.create(String.class, (req, res, str) -> { int result = 100 / Integer.parseInt(str); res.send(String.valueOf("100 / " + str + " = " + result)); })) .error(Throwable.class, (req, res, ex) -> { ex.printStackTrace(System.out); req.next(); }) .error(NumberFormatException.class, (req, res, ex) -> res.status(Http.Status.BAD_REQUEST_400).send()) .error(ArithmeticException.class, (req, res, ex) -> res.status(Http.Status.PRECONDITION_FAILED_412).send()) .build(); startServer(routing); }  void firstRouting(); void routingAsFilter(); void parametersAndHeaders(); void advancedRouting(); void organiseCode(); void readContentEntity(); void mediaReader(); void supports(); void errorHandling(); void help(); void h(); static void main(String[] args); }
Main { public void errorHandling() { Routing routing = Routing.builder() .post("/compute", Handler.create(String.class, (req, res, str) -> { int result = 100 / Integer.parseInt(str); res.send(String.valueOf("100 / " + str + " = " + result)); })) .error(Throwable.class, (req, res, ex) -> { ex.printStackTrace(System.out); req.next(); }) .error(NumberFormatException.class, (req, res, ex) -> res.status(Http.Status.BAD_REQUEST_400).send()) .error(ArithmeticException.class, (req, res, ex) -> res.status(Http.Status.PRECONDITION_FAILED_412).send()) .build(); startServer(routing); }  void firstRouting(); void routingAsFilter(); void parametersAndHeaders(); void advancedRouting(); void organiseCode(); void readContentEntity(); void mediaReader(); void supports(); void errorHandling(); void help(); void h(); static void main(String[] args);  }