wujimin commented on a change in pull request #985: [SCB-1014] Fix priority of
ExceptionToResponseConverter
URL:
https://github.com/apache/servicecomb-java-chassis/pull/985#discussion_r232515285
##########
File path:
swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/exception/ExceptionToProducerResponseConverters.java
##########
@@ -23,31 +23,37 @@
import org.apache.servicecomb.swagger.invocation.Response;
import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-public class ExceptionToResponseConverters {
- private Map<Class<?>, ExceptionToResponseConverter<Throwable>>
exceptionToResponseConverters =
+public class ExceptionToProducerResponseConverters {
+ private Map<Class<?>, ExceptionToProducerResponseConverter<Throwable>>
exceptionToProducerResponseConverters =
new HashMap<>();
- private ExceptionToResponseConverter<Throwable> defaultConverter;
+ private ExceptionToProducerResponseConverter<Throwable> defaultConverter;
+ /**
+ * Load the {@link ExceptionToProducerResponseConverter} implementations.
Ensure that those converters whose {@link
ExceptionToProducerResponseConverter#getOrder()}
+ * return smaller value takes higher priority.
+ */
@SuppressWarnings("unchecked")
- public ExceptionToResponseConverters() {
-
SPIServiceUtils.getSortedService(ExceptionToResponseConverter.class).forEach(converter
-> {
+ public ExceptionToProducerResponseConverters() {
+
SPIServiceUtils.getSortedService(ExceptionToProducerResponseConverter.class).forEach(converter
-> {
if (converter.getExceptionClass() == null) {
if (defaultConverter == null) {
defaultConverter = converter;
}
return;
}
- exceptionToResponseConverters.put(converter.getExceptionClass(),
converter);
+ if
(!exceptionToProducerResponseConverters.containsKey(converter.getExceptionClass()))
{
Review comment:
java.util.Map#putIfAbsent
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services