imbajin commented on code in PR #3029: URL: https://github.com/apache/hugegraph/pull/3029#discussion_r4614374605
########## hugegraph-pd/hg-pd-service/src/main/java/org/apache/hugegraph/pd/rest/exceptionshandler/GenericExceptionMapper.java: ########## @@ -0,0 +1,48 @@ +/* + * 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.hugegraph.pd.rest.exceptionshandler; + +import org.apache.hugegraph.rest.response.ApiResponse; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@RestControllerAdvice +public class GenericExceptionMapper { + + private static final Logger logger = LogManager.getLogger(GenericExceptionMapper.class); + + @ExceptionHandler(Exception.class) + public ResponseEntity<ApiResponse<Object>>handleGenericException(Exception exception) { Review Comment: **⚠️ Preserve client error statuses in the fallback** Spring MVC binding failures also reach this catch-all handler. For example, a nonnumeric store ID cannot bind to the `long` path parameter and would normally produce HTTP 400, but this handler returns 500. The Store fallback has the same issue, so malformed client requests appear as server failures. Please preserve the status of framework request exceptions and reserve 500 for unexpected failures; exercise the behavior through MVC requests. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
