Skip to content
Snippets Groups Projects
Commit 8a6fa3fc authored by Otto Visser's avatar Otto Visser
Browse files

Merge branch 'error-pages' into 'development'

Add error pages for different errors

Closes #93

See merge request !110
parents 6052b040 a78c79e4
Branches
Tags
2 merge requests!112Dev to master,!110Add error pages for different errors
......@@ -8,7 +8,7 @@ version = "2.0.0"
val javaVersion = JavaVersion.VERSION_11
val labradoorVersion = "1.0.8-SNAPSHOT3"
val labradoorVersion = "1.0.8-SNAPSHOT4"
val libradorVersion = "1.0.3-SNAPSHOT7"
val samlVersion = "1.17"
val springBootVersion: String = "2.4.4"
......
......
......@@ -17,13 +17,27 @@
*/
package nl.tudelft.submit.controller;
import javax.servlet.http.HttpServletResponse;
import nl.tudelft.librador.exception.DTOValidationException;
import nl.tudelft.submit.exception.DisallowedUploadException;
import nl.tudelft.submit.exception.ScoreFormatException;
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.reactive.function.client.WebClientResponseException;
import org.springframework.web.server.ResponseStatusException;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
import io.sentry.Sentry;
@ControllerAdvice
public class ErrorController {
public class ErrorController extends ResponseEntityExceptionHandler {
/**
* Prints the exception stack trace and returns the error page with the default error message.
*
......@@ -31,10 +45,88 @@ public class ErrorController {
* @return the link to the error page
*/
@ExceptionHandler(Exception.class)
public void exception(Exception e) throws Exception {
public String exception(Exception e) throws Exception {
e.printStackTrace();
Sentry.captureException(e);
throw (e);
return "error/error";
}
/**
* Returns the error page when a request is forbidden.
*
* @return The page to load
*/
@ResponseStatus(HttpStatus.FORBIDDEN)
@ExceptionHandler(AccessDeniedException.class)
public String forbidden() {
return "error/forbidden";
}
/**
* Returns the error page when a resource is not found.
*
* @return The page to load
*/
@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(ResourceNotFoundException.class)
public String notFound() {
return "error/not_found";
}
/**
* Returns the error page when a request is a bad request.
*
* @return The page to load
*/
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler({ WebClientResponseException.BadRequest.class, DisallowedUploadException.class,
ScoreFormatException.class })
public String badRequest() {
return "error/bad_request";
}
/**
* Returns the error page when a request contains an invalid entity.
*
* @return The page to load
*/
@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
@ExceptionHandler(DTOValidationException.class)
public String unprocessableEntity() {
return "error/unprocessable_entity";
}
/**
* Handles a response status exception.
*
* @return The page to load
*/
@ExceptionHandler(ResponseStatusException.class)
public String responseStatusException(ResponseStatusException e, HttpServletResponse resp)
throws Exception {
resp.setStatus(e.getStatus().value());
switch (e.getStatus()) {
case FORBIDDEN:
return forbidden();
case NOT_FOUND:
return notFound();
case UNPROCESSABLE_ENTITY:
return unprocessableEntity();
default:
return exception(e);
}
}
/**
* Handles any leftover exceptions.
*
* @return The page to load
*/
@GetMapping("/error")
public String defaultErrorMappingHandler(Exception e) throws Exception {
return exception(e);
}
}
......@@ -41,19 +41,6 @@ public class HomeController {
return person == null ? "index" : "redirect:edition/enrolled";
}
/**
* Returns the error page.
*
* @param person The authenticated person, or null if the user is not authenticated
* @param model The model to add details to
* @return the link to the error page
*/
@GetMapping("/error")
public String errorPage(@AuthenticatedPerson(required = false) Person person, Model model) {
model.addAttribute("authPerson", person);
return "error";
}
/**
* Returns the privacy statement page.
*
......
......
<!--
Submit
Copyright (C) 2020 - Delft University of Technology
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{container}">
<head>
<title th:text="#{general.app_name}"></title>
</head>
<body>
<div layout:fragment="sidebar" class="hidden"></div>
<div layout:fragment="breadcrumbs" class="hidden"></div>
<div layout:fragment="content">
<h1 class="title">Bad request</h1>
</div>
</body>
</html>
\ No newline at end of file
......@@ -32,6 +32,10 @@
<div layout:fragment="content">
<h1 class="title">Oops! Something went wrong :(</h1>
<p>Do you want to help resolve this error?
<a href="https://gitlab.ewi.tudelft.nl/eip/labrador/submit" class="text-button">Submit</a> is open source.
You can file a bug report or contribute yourself!
</p>
</div>
......
......
<!--
Submit
Copyright (C) 2020 - Delft University of Technology
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{container}">
<head>
<title th:text="#{general.app_name}"></title>
</head>
<body>
<div layout:fragment="sidebar" class="hidden"></div>
<div layout:fragment="breadcrumbs" class="hidden"></div>
<div layout:fragment="content">
<h1 class="title">You are not authorised to do that.</h1>
</div>
</body>
</html>
\ No newline at end of file
<!--
Submit
Copyright (C) 2020 - Delft University of Technology
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{container}">
<head>
<title th:text="#{general.app_name}"></title>
</head>
<body>
<div layout:fragment="sidebar" class="hidden"></div>
<div layout:fragment="breadcrumbs" class="hidden"></div>
<div layout:fragment="content">
<h1 class="title">What you are looking for is not (yet) there.</h1>
</div>
</body>
</html>
\ No newline at end of file
<!--
Submit
Copyright (C) 2020 - Delft University of Technology
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{container}">
<head>
<title th:text="#{general.app_name}"></title>
</head>
<body>
<div layout:fragment="sidebar" class="hidden"></div>
<div layout:fragment="breadcrumbs" class="hidden"></div>
<div layout:fragment="content">
<h1 class="title">Entity was not valid</h1>
</div>
</body>
</html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment