Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
ec-simple
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
0Tyler
ec-simple
Commits
4c1fa687
Commit
4c1fa687
authored
Jul 18, 2022
by
0Tyler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: global error handler for debug
parent
b5e22fc2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
13 deletions
+17
-13
src/main/java/edu/prlab/ecsimple/common/handler/RestExceptionHandler.java
...u/prlab/ecsimple/common/handler/RestExceptionHandler.java
+14
-11
src/main/java/edu/prlab/ecsimple/config/SecurityConfig.java
src/main/java/edu/prlab/ecsimple/config/SecurityConfig.java
+2
-1
src/main/java/edu/prlab/ecsimple/service/OrderServiceImpl.java
...ain/java/edu/prlab/ecsimple/service/OrderServiceImpl.java
+1
-1
No files found.
src/main/java/edu/prlab/ecsimple/common/handler/RestExceptionHandler.java
View file @
4c1fa687
...
...
@@ -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);
//
}
}
src/main/java/edu/prlab/ecsimple/config/SecurityConfig.java
View file @
4c1fa687
...
...
@@ -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
();
}
...
...
src/main/java/edu/prlab/ecsimple/service/OrderServiceImpl.java
View file @
4c1fa687
...
...
@@ -70,7 +70,7 @@ public class OrderServiceImpl implements OrderService {
.
map
(
order
->
{
Collection
<
LineItem
>
lineItems
=
orderModel
.
getLineItems
().
stream
()
.
map
(
it
->
addItemFromProduct
(
it
)
.
orElseThrow
(()
->
new
Runtime
Exception
(
"Save lineItem error"
)))
.
orElseThrow
(()
->
new
Business
Exception
(
"Save lineItem error"
)))
.
peek
(
it
->
addItemToOrder
(
order
.
getIid
(),
it
.
getSku
()))
.
collect
(
Collectors
.
toList
());
order
.
setLineItems
(
lineItems
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment