diff --git a/samples/sample-spring-boot-kitchensink/src/main/java/com/example/bot/spring/KitchenSinkController.java b/samples/sample-spring-boot-kitchensink/src/main/java/com/example/bot/spring/KitchenSinkController.java index 0d2778f02..2464e312e 100644 --- a/samples/sample-spring-boot-kitchensink/src/main/java/com/example/bot/spring/KitchenSinkController.java +++ b/samples/sample-spring-boot-kitchensink/src/main/java/com/example/bot/spring/KitchenSinkController.java @@ -637,6 +637,22 @@ private void handleTextContent(String replyToken, MessageEvent event, TextMessag "Hello, I'm cat! Meow~", null, null)); + case "error" -> { + // demonstrate the case of the invalid request. + // and proper error handling. + + // You will get an exception like this: + // + // Caused by: java.lang.RuntimeException: java.util.concurrent.ExecutionException: \ + // com.linecorp.bot.messaging.client.MessagingApiClientException: API returns error: \ + // code=400 requestUrl=https://api.line.me/v2/bot/message/reply \ + // requestId=f3610029-302a-4fc3-8238-d3d6deadbeef error='Invalid reply token' details='null' + try { + this.reply(replyToken + "invalid", new TextMessage("Request error")); + } catch (RuntimeException e) { + log.info("Got an exception: " + e.getMessage(), e); + } + } default -> { log.info("Returns echo message {}: {}", replyToken, text); this.replyText(