Skip to content
Snippets Groups Projects
Commit 1fd47588 authored by Klaus-Dieter Quibeldey-Cirkel's avatar Klaus-Dieter Quibeldey-Cirkel
Browse files

Merge pull request #27 from pcvolkmer/defaultExceptionHandler

Add a default exception handler to catch non handled exceptions
parents b8bee647 56fe085e
Branches
Tags
No related merge requests found
......@@ -17,6 +17,9 @@
*/
package de.thm.arsnova.controller;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
......@@ -35,9 +38,9 @@ import de.thm.arsnova.exceptions.ForbiddenException;
import de.thm.arsnova.exceptions.NoContentException;
import de.thm.arsnova.exceptions.NotFoundException;
import de.thm.arsnova.exceptions.NotImplementedException;
import de.thm.arsnova.exceptions.PayloadTooLargeException;
import de.thm.arsnova.exceptions.PreconditionFailedException;
import de.thm.arsnova.exceptions.UnauthorizedException;
import de.thm.arsnova.exceptions.PayloadTooLargeException;
/**
* Translates security/authentication related exceptions into HTTP status codes.
......@@ -45,6 +48,19 @@ import de.thm.arsnova.exceptions.PayloadTooLargeException;
@ControllerAdvice
public class SecurityExceptionControllerAdvice {
@ExceptionHandler
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public Map<String,String> defaultExceptionHandler(
final Exception e,
final HttpServletRequest req
) {
final Map<String, String> result = new HashMap<String, String>();
result.put("code", "500");
result.put("status", "Internal server error");
result.put("message", e.getMessage());
return result;
}
@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(NotFoundException.class)
public void handleNotFoundException(final Exception e, final HttpServletRequest request) {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment