Commit 4c1fa687 authored by 0Tyler's avatar 0Tyler

feat: global error handler for debug

parent b5e22fc2
......@@ -13,21 +13,24 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
/**
* 全域錯誤處理
*/
@Order(Ordered.HIGHEST_PRECEDENCE)
@ControllerAdvice
@Slf4j
public class RestExceptionHandler extends ResponseEntityExceptionHandler {
@ExceptionHandler(Exception.class)
protected ResponseEntity<Object> handleAll(Exception ex, WebRequest request) {
ex.printStackTrace();
return handleExceptionInternal(ex, ex.getMessage(), new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR, request);
}
// @ExceptionHandler(Exception.class)
// protected ResponseEntity<Object> handleAll(Exception ex, WebRequest request) {
// ex.printStackTrace();
// return handleExceptionInternal(ex, ex.getMessage(), new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR, request);
// }
@NonNull
@Override
protected ResponseEntity<Object> handleHttpMessageNotReadable(
@NonNull HttpMessageNotReadableException ex, @NonNull HttpHeaders headers, @NonNull HttpStatus status, @NonNull WebRequest request) {
return new ResponseEntity<>(ex.getMessage(), new HttpHeaders(), HttpStatus.BAD_REQUEST);
}
// @NonNull
// @Override
// protected ResponseEntity<Object> handleHttpMessageNotReadable(
// @NonNull HttpMessageNotReadableException ex, @NonNull HttpHeaders headers, @NonNull HttpStatus status, @NonNull WebRequest request) {
// return new ResponseEntity<>(ex.getMessage(), new HttpHeaders(), HttpStatus.BAD_REQUEST);
// }
}
......@@ -59,7 +59,8 @@ public class SecurityConfig {
.and()
.addFilterBefore(jwtAuthorizationFilter(), UsernamePasswordAuthenticationFilter.class)
.addFilter(new JwtAuthorizationFilter(authenticationManager, jwtTokenProvider))
.authorizeRequests();
.authorizeRequests()
.anyRequest().authenticated();
http.headers().frameOptions().disable();
return http.build();
}
......
......@@ -70,7 +70,7 @@ public class OrderServiceImpl implements OrderService {
.map(order -> {
Collection<LineItem> lineItems = orderModel.getLineItems().stream()
.map(it -> addItemFromProduct(it)
.orElseThrow(() -> new RuntimeException("Save lineItem error")))
.orElseThrow(() -> new BusinessException("Save lineItem error")))
.peek(it -> addItemToOrder(order.getIid(), it.getSku()))
.collect(Collectors.toList());
order.setLineItems(lineItems);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment