Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java_weekendowa_20221008
Overview
Overview
Details
Activity
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
Patryk Czarnik
java_weekendowa_20221008
Commits
f6323f3b
Commit
f6323f3b
authored
Dec 11, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ExceptionMapper
parent
38307388
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
0 deletions
+55
-0
RecordNotFoundMapper.java
...stSerwer/src/main/java/rest/ext/RecordNotFoundMapper.java
+23
-0
SklepExceptionMapper.java
...stSerwer/src/main/java/rest/ext/SklepExceptionMapper.java
+32
-0
No files found.
PC35-RestSerwer/src/main/java/rest/ext/RecordNotFoundMapper.java
0 → 100644
View file @
f6323f3b
package
rest
.
ext
;
import
javax.ws.rs.core.Response
;
import
javax.ws.rs.ext.ExceptionMapper
;
import
javax.ws.rs.ext.Provider
;
import
sklep.db.RecordNotFound
;
@Provider
public
class
RecordNotFoundMapper
implements
ExceptionMapper
<
RecordNotFound
>
{
@Override
public
Response
toResponse
(
RecordNotFound
exception
)
{
String
html
=
"<html><body><h1>Nie znaleziono</h1><p style='color:red'>"
+
exception
.
getMessage
()
+
"</p></body></html>"
;
return
Response
.
status
(
404
)
.
type
(
"text/html;charset=utf-8"
)
.
entity
(
html
)
.
build
();
}
}
PC35-RestSerwer/src/main/java/rest/ext/SklepExceptionMapper.java
0 → 100644
View file @
f6323f3b
package
rest
.
ext
;
import
javax.ws.rs.core.Response
;
import
javax.ws.rs.core.Response.Status
;
import
javax.ws.rs.ext.ExceptionMapper
;
import
javax.ws.rs.ext.Provider
;
import
sklep.db.SklepException
;
@Provider
public
class
SklepExceptionMapper
implements
ExceptionMapper
<
SklepException
>
{
@Override
public
Response
toResponse
(
SklepException
e
)
{
String
tresc
=
String
.
format
(
"<html><body>"
+
"<h1>Błąd</h1>"
+
"<div>Błąd typu <code>%s</code></div>"
+
"<div style='color:red'>%s</div>"
+
"</body></html>"
,
e
.
getClass
().
getName
(),
e
.
getMessage
());
return
Response
.
status
(
Status
.
INTERNAL_SERVER_ERROR
)
.
type
(
"text/html;charset=utf-8"
)
.
entity
(
tresc
)
.
build
();
}
}
// a gdybyśmy chcieli mapować wszystkie wyjątki
// public class DefaultExceptionMapper implements ExceptionMapper<Exception> { ... }
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