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"?> <?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"> 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> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version> <version>3.3.5</version>
<relativePath/> <!-- lookup parent from repository --> <relativePath /> <!-- lookup parent from repository -->
</parent> </parent>
<groupId>com.maradona</groupId> <groupId>com.maradona</groupId>
<artifactId>backend</artifactId> <artifactId>backend</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<name>backend</name> <name>backend</name>
<description>Demo project for Spring Boot</description> <description>Demo project for Spring Boot</description>
<url/> <url />
<licenses> <licenses>
<license/> <license />
</licenses> </licenses>
<developers> <developers>
<developer/> <developer />
</developers> </developers>
<scm> <scm>
<connection/> <connection />
<developerConnection/> <developerConnection />
<tag/> <tag />
<url/> <url />
</scm> </scm>
<properties> <properties>
<java.version>21</java.version> <java.version>21</java.version>
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId> <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId> <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency> </dependency>
<!-- <dependency> <!-- <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId> <artifactId>spring-boot-starter-security</artifactId>
</dependency> --> </dependency> -->
<dependency> <dependency>
<groupId>org.thymeleaf.extras</groupId> <groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity6</artifactId> <artifactId>thymeleaf-extras-springsecurity6</artifactId>
</dependency> </dependency>
<!-- <dependency> <!-- <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId> <artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency> --> </dependency> -->
<!-- <dependency> <!-- <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId> <artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
</dependency> --> </dependency> -->
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<version>1.18.30</version> <version>1.18.30</version>
<scope>provided</scope> <scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency> </dependency>
@ -77,6 +93,7 @@
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.security</groupId> <groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId> <artifactId>spring-security-test</artifactId>
@ -91,17 +108,17 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
<configuration> <configuration>
<classifier>exec</classifier> <classifier>exec</classifier>
</configuration> </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>
<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> </plugins>
</build> </build>

View File

@ -1,58 +1,23 @@
package com.maradona.backend.controllers.page; package com.maradona.backend.controllers.page;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
/** import javax.servlet.http.HttpServletRequest;
* Controller for routing to the error pages.
*
* List of endpoints:
* - GET /error/400
* - GET /error/404
* - GET /error/500
*/
@Controller @Controller
@RequestMapping("/error") public class ErrorPage implements ErrorController {
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";
}
/** @RequestMapping("/error")
* Error page for 404 Not Found. public String handleError(HttpServletRequest request, Model model) {
* Object status = request.getAttribute("javax.servlet.error.status_code");
* This page is displayed when the requested resource could not be found on the Object message = request.getAttribute("javax.servlet.error.message");
* 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";
}
/** model.addAttribute("status", status);
* Error page for 500 Internal Server Error. model.addAttribute("message", message);
*
* This page is displayed when the server encountered an unexpected condition return "pages/core/error";
* 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";
}
} }

View File

@ -45,14 +45,4 @@ public class Page {
public String datenschutz() { public String datenschutz() {
return "pages/core/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: http:
converter: converter:
json: DEBUG json: DEBUG
server:
error:
path: /error
whitelabel:
enabled: false