Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
promotions-service
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ascend
promotions-service
Commits
ae8d9aba
Commit
ae8d9aba
authored
May 06, 2021
by
Ben Anderson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added error message to error response
parent
1e87cd4f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
3 deletions
+12
-3
PromotionsController.java
...um/ascend/promotions/controller/PromotionsController.java
+1
-1
PromotionNotFoundException.java
...cend/promotions/exception/PromotionNotFoundException.java
+4
-0
RestWebExceptionHandler.java
.../ascend/promotions/exception/RestWebExceptionHandler.java
+7
-2
No files found.
src/main/java/com/nisum/ascend/promotions/controller/PromotionsController.java
View file @
ae8d9aba
...
...
@@ -32,7 +32,7 @@ public class PromotionsController {
public
Mono
<
PromotionDto
>
getPromotionById
(
@PathVariable
String
id
){
return
promotionService
.
findPromoById
(
id
)
.
onErrorMap
(
throwable
->
new
PromotionNotFoundException
(
id
));
.
switchIfEmpty
(
Mono
.
error
(
new
PromotionNotFoundException
(
id
)
));
}
@PostMapping
()
...
...
src/main/java/com/nisum/ascend/promotions/exception/PromotionNotFoundException.java
View file @
ae8d9aba
package
com
.
nisum
.
ascend
.
promotions
.
exception
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.bind.annotation.ResponseStatus
;
@ResponseStatus
(
value
=
HttpStatus
.
NOT_FOUND
)
public
class
PromotionNotFoundException
extends
RuntimeException
{
public
PromotionNotFoundException
(
String
id
)
{
super
(
"The promotion with the ID of "
+
id
+
" was not found."
);
...
...
src/main/java/com/nisum/ascend/promotions/exception/RestWebExceptionHandler.java
View file @
ae8d9aba
package
com
.
nisum
.
ascend
.
promotions
.
exception
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.core.io.buffer.DataBuffer
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.server.ServerWebExchange
;
import
org.springframework.web.server.WebExceptionHandler
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
import
springfox.documentation.spring.web.json.Json
;
import
java.nio.charset.StandardCharsets
;
@Component
@Order
(-
2
)
...
...
@@ -15,9 +20,9 @@ class RestWebExceptionHandler implements WebExceptionHandler {
public
Mono
<
Void
>
handle
(
ServerWebExchange
exchange
,
Throwable
ex
)
{
if
(
ex
instanceof
PromotionNotFoundException
)
{
exchange
.
getResponse
().
setStatusCode
(
HttpStatus
.
NOT_FOUND
);
DataBuffer
buffer
=
exchange
.
getResponse
().
bufferFactory
().
wrap
(
ex
.
getMessage
().
getBytes
(
StandardCharsets
.
UTF_8
));
// marks the response as complete and forbids writing to it
return
exchange
.
getResponse
().
setComplete
(
);
return
exchange
.
getResponse
().
writeWith
(
Flux
.
just
(
buffer
)
);
}
return
Mono
.
error
(
ex
);
}
...
...
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