Skip to content

Commit fc1486f

Browse files
tokuhiromYang-33
andauthored
add error handling case to kitchensink (#1156)
Co-authored-by: Yuta Kasai <[email protected]>
1 parent 160ff63 commit fc1486f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

samples/sample-spring-boot-kitchensink/src/main/java/com/example/bot/spring/KitchenSinkController.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,22 @@ private void handleTextContent(String replyToken, MessageEvent event, TextMessag
637637
"Hello, I'm cat! Meow~",
638638
null,
639639
null));
640+
case "error" -> {
641+
// demonstrate the case of the invalid request.
642+
// and proper error handling.
643+
644+
// You will get an exception like this:
645+
//
646+
// Caused by: java.lang.RuntimeException: java.util.concurrent.ExecutionException: \
647+
// com.linecorp.bot.messaging.client.MessagingApiClientException: API returns error: \
648+
// code=400 requestUrl=https://api.line.me/v2/bot/message/reply \
649+
// requestId=f3610029-302a-4fc3-8238-d3d6deadbeef error='Invalid reply token' details='null'
650+
try {
651+
this.reply(replyToken + "invalid", new TextMessage("Request error"));
652+
} catch (RuntimeException e) {
653+
log.info("Got an exception: " + e.getMessage(), e);
654+
}
655+
}
640656
default -> {
641657
log.info("Returns echo message {}: {}", replyToken, text);
642658
this.replyText(

0 commit comments

Comments
 (0)