Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit 8e83ad1

Browse files
committed
added custom error controller
1 parent 3689072 commit 8e83ad1

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package de.filefighter.rest.rest;
2+
3+
import org.springframework.boot.web.servlet.error.ErrorController;
4+
import org.springframework.hateoas.EntityModel;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.RestController;
7+
import springfox.documentation.annotations.ApiIgnore;
8+
9+
@ApiIgnore
10+
@RestController
11+
public class RestErrorController implements ErrorController {
12+
13+
private static final String DEFAULT_PATH = "/error";
14+
15+
@RequestMapping(value = DEFAULT_PATH)
16+
public EntityModel<ServerResponse> error() {
17+
return new ServerResponse("denied", "This endpoint does not exist.").toModel();
18+
}
19+
20+
@Override
21+
public String getErrorPath() {
22+
return DEFAULT_PATH;
23+
}
24+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package de.filefighter.rest.rest;
2+
3+
import lombok.Data;
4+
import org.springframework.hateoas.EntityModel;
5+
6+
@Data
7+
public class ServerResponse {
8+
private String message;
9+
private String status;
10+
11+
public ServerResponse(String status, String message) {
12+
this.status = status;
13+
this.message = message;
14+
}
15+
16+
public EntityModel<ServerResponse> toModel() {
17+
return EntityModel.of(this);
18+
}
19+
}

0 commit comments

Comments
 (0)