api: Error stuff

pull/1/head
Lunix-420 2024-11-12 23:59:55 +01:00
parent c5c8797ba2
commit a2fc1b44e5
4 changed files with 62 additions and 85 deletions

65
pom.xml
View File

@ -1,68 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<relativePath/> <!-- lookup parent from repository -->
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.maradona</groupId>
<artifactId>backend</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>backend</name>
<description>Demo project for Spring Boot</description>
<url/>
<url />
<licenses>
<license/>
<license />
</licenses>
<developers>
<developer/>
<developer />
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
<connection />
<developerConnection />
<tag />
<url />
</scm>
<properties>
<java.version>21</java.version>
</properties>
<dependencies>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency> -->
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity6</artifactId>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency> -->
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
</dependency> -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<scope>provided</scope>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
@ -77,6 +93,7 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
@ -91,17 +108,17 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.1</version>
<configuration>
<destDir>${project.build.directory}/docs</destDir>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.1</version>
<configuration>
<destDir>${project.build.directory}/docs</destDir>
</configuration>
</plugin>
</plugins>
</build>

View File

@ -1,58 +1,23 @@
package com.maradona.backend.controllers.page;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* Controller for routing to the error pages.
*
* List of endpoints:
* - GET /error/400
* - GET /error/404
* - GET /error/500
*/
import javax.servlet.http.HttpServletRequest;
@Controller
@RequestMapping("/error")
public class ErrorPage {
/**
* Error page for 400 Bad Request.
*
* This page is displayed when the request is malformed and the server cannot
* process it.
*
* @return The 400 error page template.
*/
@GetMapping("/400")
public String error400() {
return "pages/error/400";
}
public class ErrorPage implements ErrorController {
/**
* Error page for 404 Not Found.
*
* This page is displayed when the requested resource could not be found on the
* server. This can be due to a wrong URL or a deleted resource. The user should
* be informed that the resource is not available.
*
* @return The 404 error page template.
*/
@GetMapping("/404")
public String error404() {
return "pages/error/404";
}
@RequestMapping("/error")
public String handleError(HttpServletRequest request, Model model) {
Object status = request.getAttribute("javax.servlet.error.status_code");
Object message = request.getAttribute("javax.servlet.error.message");
/**
* Error page for 500 Internal Server Error.
*
* This page is displayed when the server encountered an unexpected condition
* that prevented it from fulfilling the request. The user should be informed
* that the server is experiencing problems and the request cannot be processed.
*
* @return The 500 error page template.
*/
@GetMapping("/500")
public String error500() {
return "pages/error/500";
}
model.addAttribute("status", status);
model.addAttribute("message", message);
return "pages/core/error";
}
}

View File

@ -45,14 +45,4 @@ public class Page {
public String datenschutz() {
return "pages/core/datenschutz";
}
/**
* Returns the notes page.
*
* @return The notes page template.
*/
@GetMapping("/notes")
public String notes() {
return "pages/core/notes";
}
}

View File

@ -43,3 +43,8 @@ logging:
http:
converter:
json: DEBUG
server:
error:
path: /error
whitelabel:
enabled: false