Tiven Wang
Wang Tiven July 11, 2017
425 favorite favorites
bookmark bookmark
share share

Controller Advice

@ControllerAdvice

@ExceptionHandler(ResourceNotFoundException.class)
public ResponseEntity<?> resourceNotFound(ResourceNotFoundException ex, HttpServletRequest request) {
	ErrorDetail errorDetail = new ErrorDetail();
	errorDetail.setTimeStamp(new Date().getTime());
	errorDetail.setStatus(HttpStatus.NOT_FOUND.value());
	errorDetail.setTitle("Resource Not Found");
	errorDetail.setDetail(ex.getMessage());
	errorDetail.setDeveloperMessage(ex.getClass().getName());

	return new ResponseEntity<>(errorDetail, null, HttpStatus.NOT_FOUND);
}

Handle Error in Client

References

Similar Posts

  • Microservices - Inter-Process Communication The kernal of Microservices Architecture is inter-process communication
  • Microservices - API Gateway : Spring Cloud Gateway Spring Cloud Gateway 是一个新的基于 Spring Framework 5, Project Reactor and Spring Boot 2.0 的 API Gateway 产品
  • Microservices - API Gateway : Zuul Zuul 是来自 NetFlix 的 Microservice 产品家族的 API Gateway 服务或者说是 edge 服务。 Zuul 为开发者构建微服务架构提供了 Routing,Monitoring,Managing resiliency,Security等功能。简单来说,Zuul 可以被看作是一个反向代理,在服务实例间 Zuul 代理内部使用 Eureka server 作为 service discovery,使用Ribbon 作为 load balancing
  • Microservices - Transactions
  • Microservices - API Gateway Implement an API gateway that is the single entry point for all clients. The API gateway handles requests in one of two ways. Some requests are simply proxied/routed to the appropriate service. It handles other requests by fanning out to multiple services.
  • Microservices - Circuit Breaker 访问远程服务时, 比依赖超时时间更好一些的方式是一种叫断路器(Circuit Breaker)的模式. Circuit Breaker 就像一位交通警察, 在前方道路畅通的情况下, 他会放行; 当前方道路由于各种原因拥堵时, 他会告诉你前方道路不通请回; 如果他是个更智能的交警的话, 还会告诉你前方道路部分拥堵, 只允许部分车辆通过, 比如实行单双号.

Comments

Back to Top