RockteMQ-AI commented on PR #2949:
URL: 
https://github.com/apache/rocketmq-dashboard/pull/2949#issuecomment-5502550176

   bash: line 162: BusinessException: command not found
   bash: line 162: GlobalExceptionHandler: command not found
   bash: command substitution: line 162: syntax error near unexpected token 
`code'
   bash: command substitution: line 162: `ResponseEntity.status(code)'
   bash: command substitution: line 162: syntax error near unexpected token 
`code'
   bash: command substitution: line 162: `HttpStatus.valueOf(code)'
   bash: line 162: cd: server: No such file or directory
   bash: line 162: cd: server: No such file or directory
   bash: command substitution: line 162: syntax error near unexpected token `('
   bash: command substitution: line 162: ` diff --git 
a/server/src/main/java/org/apache/rocketmq/studio/common/exception/BusinessException.java
 
b/server/src/main/java/org/apache/rocketmq/studio/common/exception/BusinessException.java
 index 2fcbb55d6..f14c92659 100644 --- 
a/server/src/main/java/org/apache/rocketmq/studio/common/exception/BusinessException.java
 +++ 
b/server/src/main/java/org/apache/rocketmq/studio/common/exception/BusinessException.java
 @@ -24,6 +24,9 @@ public class BusinessException extends RuntimeException {    
    public BusinessException(int code, String message) {          
super(message); -        this.code = code; +        // The global exception 
handler maps the code directly onto the HTTP status line, so it +        // 
must stay in the 4xx/5xx band: a 2xx/3xx code would answer the error with a 
success +        // or redirect status, and a code outside the band makes 
HttpStatus.valueOf throw. +        this.code = code >= 400 && code <= 599 ? 
code : 400;      } 
  } diff --git 
a/server/src/test/java/org/apache/rocketmq/studio/common/exception/BusinessExceptionTest.java
 
b/server/src/test/java/org/apache/rocketmq/studio/common/exception/BusinessExceptionTest.java
 new file mode 100644 index 000000000..5e0b1159d --- /dev/null +++ 
b/server/src/test/java/org/apache/rocketmq/studio/common/exception/BusinessExceptionTest.java
 @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) 
under one or more + * contributor license agreements.  See the NOTICE file 
distributed with + * this work for additional information regarding copyright 
ownership. + * The ASF licenses this file to You under the Apache License, 
Version 2.0 + * (the "License"); you may not use this file except in compliance 
with + * the License.  You may obtain a copy of the License at + * + *     
http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by 
applicable law or agreed to in writing, software + * distributed under the 
License is distributed on an "AS 
 IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
implied. + * See the License for the specific language governing permissions 
and + * limitations under the License. + */ +package 
org.apache.rocketmq.studio.common.exception; + +import 
org.junit.jupiter.api.Test; + +import static 
org.assertj.core.api.Assertions.assertThat; + +class BusinessExceptionTest { + 
+    @Test +    void codesWithinTheErrorBandsShouldPassThrough() { +        
assertThat(new BusinessException(400, "bad").getCode()).isEqualTo(400); +       
 assertThat(new BusinessException(401, "auth").getCode()).isEqualTo(401); +     
   assertThat(new BusinessException(404, "missing").getCode()).isEqualTo(404); 
+        assertThat(new BusinessException(422, 
"unprocessable").getCode()).isEqualTo(422); +        assertThat(new 
BusinessException(502, "upstream").getCode()).isEqualTo(502); +        
assertThat(new BusinessException(599, "upper bound").getCode()).isEqualTo(599); 
+    } + +    @Test +    voi
 d codesOutsideTheErrorBandsShouldFallBackToBadRequest() { +        
assertThat(new BusinessException(0, "zero").getCode()).isEqualTo(400); +        
assertThat(new BusinessException(200, 
"success-looking").getCode()).isEqualTo(400); +        assertThat(new 
BusinessException(301, "redirect-looking").getCode()).isEqualTo(400); +        
assertThat(new BusinessException(600, "future").getCode()).isEqualTo(400); +    
    assertThat(new BusinessException(-7, "negative").getCode()).isEqualTo(400); 
+    } + +    @Test +    void messageShouldPassThroughUnchanged() { +        
BusinessException exception = new BusinessException(404, "row not found"); + +  
      assertThat(exception.getMessage()).isEqualTo("row not found"); +    } +} '
   ## Summary
   Normalizes `BusinessException` codes to 4xx/5xx, otherwise using 400, with 
constructor-level regression tests.
   
   ## Findings
   - **Non-blocking** — `BusinessException.java:28-30`: the comment incorrectly 
says codes outside 4xx/5xx make `HttpStatus.valueOf` throw. Spring Boot 3.5 
uses `HttpStatusCode.valueOf(int)`, which accepts unknown three-digit codes 
such as 600. Remove or reword the rationale around HTTP error semantics.
   - **Test gap** — `BusinessExceptionTest.java:29`: add MockMvc coverage 
through `GlobalExceptionHandler.java:44` for `200` and `600`, asserting HTTP 
400 and envelope code 400.
   
   ## Assessment
   No blocking logic, thread-safety, resource-leak, API-security, or 
compatibility concerns. Existing valid 4xx/5xx behavior remains unchanged.


-- 
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