pratt4 commented on code in PR #25865:
URL: https://github.com/apache/pulsar/pull/25865#discussion_r3298550180


##########
pulsar-websocket/src/main/java/org/apache/pulsar/websocket/ReaderHandler.java:
##########
@@ -385,13 +397,25 @@ private int getReceiverQueueSize() {
         return size;
     }
 
-    private MessageId getMessageId() throws IOException {
+    private MessageId getMessageId() {
         MessageId messageId = MessageId.latest;
-        if (isNotBlank(queryParams.get("messageId"))) {
-            if (queryParams.get("messageId").equals("earliest")) {
+        String messageIdParam = queryParams.get("messageId");
+        if (isNotBlank(messageIdParam)) {
+            if (messageIdParam.equals("earliest")) {
                 messageId = MessageId.earliest;
-            } else if (!queryParams.get("messageId").equals("latest")) {
-                messageId = 
MessageIdImpl.fromByteArray(Base64.getDecoder().decode(queryParams.get("messageId")));
+            } else if (!messageIdParam.equals("latest")) {
+                final byte[] decoded;
+                try {
+                    decoded = Base64.getDecoder().decode(messageIdParam);
+                } catch (IllegalArgumentException e) {
+                    throw new IllegalArgumentException("Invalid messageId 
base64 value", e);
+                }
+
+                try {
+                    messageId = MessageIdImpl.fromByteArray(decoded);
+                } catch (IOException e) {

Review Comment:
   Thanks @lhotari , 
   
   fixed it...
   
   since IllegalStateException was not converted to IllegalArgumentException it 
would still map to 500. I updated getMessageId() to wrap runtime parse failures 
from MessageIdImpl.fromByteArray(...) as IllegalArgumentException, so they now 
return 400 as well.
   
   Please review and lmk if any other changes are needed 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to