Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ARSnova Backend
Manage
Activity
Members
Labels
Plan
Issues
27
Issue boards
Milestones
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Privacy
Imprint
Contact
Snippets
Groups
Projects
Show more breadcrumbs
ARSnova
ARSnova Backend
Commits
15ed6f79
Commit
15ed6f79
authored
7 years ago
by
Daniel Gerhardt
Browse files
Options
Downloads
Patches
Plain Diff
Improve Exception handling
parent
189670cd
1 merge request
!89
Foundation for development of version 3.0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/de/thm/arsnova/controller/ControllerExceptionHandler.java
+13
-2
13 additions, 2 deletions
...de/thm/arsnova/controller/ControllerExceptionHandler.java
with
13 additions
and
2 deletions
src/main/java/de/thm/arsnova/controller/ControllerExceptionHandler.java
+
13
−
2
View file @
15ed6f79
...
@@ -25,6 +25,7 @@ import de.thm.arsnova.exceptions.NotImplementedException;
...
@@ -25,6 +25,7 @@ import de.thm.arsnova.exceptions.NotImplementedException;
import
de.thm.arsnova.exceptions.PayloadTooLargeException
;
import
de.thm.arsnova.exceptions.PayloadTooLargeException
;
import
de.thm.arsnova.exceptions.PreconditionFailedException
;
import
de.thm.arsnova.exceptions.PreconditionFailedException
;
import
de.thm.arsnova.exceptions.UnauthorizedException
;
import
de.thm.arsnova.exceptions.UnauthorizedException
;
import
org.ektorp.DocumentNotFoundException
;
import
org.slf4j.event.Level
;
import
org.slf4j.event.Level
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.converter.HttpMessageNotReadableException
;
import
org.springframework.http.converter.HttpMessageNotReadableException
;
...
@@ -33,12 +34,14 @@ import org.springframework.security.authentication.AnonymousAuthenticationToken;
...
@@ -33,12 +34,14 @@ import org.springframework.security.authentication.AnonymousAuthenticationToken;
import
org.springframework.security.authentication.AuthenticationCredentialsNotFoundException
;
import
org.springframework.security.authentication.AuthenticationCredentialsNotFoundException
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.web.HttpRequestMethodNotSupportedException
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseStatus
;
import
org.springframework.web.bind.annotation.ResponseStatus
;
import
org.springframework.web.servlet.NoHandlerFoundException
;
import
org.springframework.web.servlet.NoHandlerFoundException
;
import
javax.naming.OperationNotSupportedException
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -109,7 +112,7 @@ public class ControllerExceptionHandler extends AbstractControllerExceptionHandl
...
@@ -109,7 +112,7 @@ public class ControllerExceptionHandler extends AbstractControllerExceptionHandl
return
handleException
(
e
,
Level
.
DEBUG
);
return
handleException
(
e
,
Level
.
DEBUG
);
}
}
@ExceptionHandler
(
BadRequestException
.
class
)
@ExceptionHandler
(
{
BadRequestException
.
class
,
HttpRequestMethodNotSupportedException
.
class
}
)
@ResponseBody
@ResponseBody
@ResponseStatus
(
HttpStatus
.
BAD_REQUEST
)
@ResponseStatus
(
HttpStatus
.
BAD_REQUEST
)
public
Map
<
String
,
Object
>
handleBadRequestException
(
final
Exception
e
,
final
HttpServletRequest
request
)
{
public
Map
<
String
,
Object
>
handleBadRequestException
(
final
Exception
e
,
final
HttpServletRequest
request
)
{
...
@@ -123,7 +126,7 @@ public class ControllerExceptionHandler extends AbstractControllerExceptionHandl
...
@@ -123,7 +126,7 @@ public class ControllerExceptionHandler extends AbstractControllerExceptionHandl
return
handleException
(
e
,
Level
.
DEBUG
);
return
handleException
(
e
,
Level
.
DEBUG
);
}
}
@ExceptionHandler
(
NotImplementedException
.
class
)
@ExceptionHandler
(
{
NotImplementedException
.
class
,
OperationNotSupportedException
.
class
}
)
@ResponseBody
@ResponseBody
@ResponseStatus
(
HttpStatus
.
NOT_IMPLEMENTED
)
@ResponseStatus
(
HttpStatus
.
NOT_IMPLEMENTED
)
public
Map
<
String
,
Object
>
handleNotImplementedException
(
final
Exception
e
,
final
HttpServletRequest
request
)
{
public
Map
<
String
,
Object
>
handleNotImplementedException
(
final
Exception
e
,
final
HttpServletRequest
request
)
{
...
@@ -143,4 +146,12 @@ public class ControllerExceptionHandler extends AbstractControllerExceptionHandl
...
@@ -143,4 +146,12 @@ public class ControllerExceptionHandler extends AbstractControllerExceptionHandl
public
Map
<
String
,
Object
>
handleHttpMessageNotReadableException
(
final
Exception
e
,
final
HttpServletRequest
request
)
{
public
Map
<
String
,
Object
>
handleHttpMessageNotReadableException
(
final
Exception
e
,
final
HttpServletRequest
request
)
{
return
handleException
(
e
,
Level
.
DEBUG
);
return
handleException
(
e
,
Level
.
DEBUG
);
}
}
/* FIXME: Wrap persistance Exceptions - do not handle persistance Exceptions at the controller layer */
@ExceptionHandler
(
DocumentNotFoundException
.
class
)
@ResponseBody
@ResponseStatus
(
HttpStatus
.
NOT_FOUND
)
public
Map
<
String
,
Object
>
handleDocumentNotFoundException
(
final
Exception
e
,
final
HttpServletRequest
request
)
{
return
handleException
(
e
,
Level
.
TRACE
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment