Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java_dzienna_15_09
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_dzienna_15_09
Commits
11b2fe2e
Commit
11b2fe2e
authored
Oct 07, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mappery wyjątków
parent
e5f29427
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
0 deletions
+53
-0
RecordNotFoundMapper.java
...er/src/main/java/sklep/rest/ext/RecordNotFoundMapper.java
+21
-0
SklepExceptionMapper.java
...er/src/main/java/sklep/rest/ext/SklepExceptionMapper.java
+32
-0
No files found.
PC34-RestSerwer/src/main/java/sklep/rest/ext/RecordNotFoundMapper.java
0 → 100644
View file @
11b2fe2e
package
sklep
.
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
e
)
{
String
html
=
"<html><body><h1>Nie znaleziono</h1><p style='color:red'>"
+
e
.
getMessage
()
+
"</p></body></html>"
;
return
Response
.
status
(
404
)
.
type
(
"text/html"
)
.
entity
(
html
)
.
build
();
}
}
PC34-RestSerwer/src/main/java/sklep/rest/ext/SklepExceptionMapper.java
0 → 100644
View file @
11b2fe2e
package
sklep
.
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