3 changed files with 74 additions and 36 deletions
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
/* |
||||
* Copyright 2002-2025 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.webmvc.mvcservlet.mvcanncustomerservletcontainererrorpage; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
import jakarta.servlet.http.HttpServletRequest; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
// tag::snippet[]
|
||||
@RestController |
||||
public class ErrorController { |
||||
|
||||
@RequestMapping(path = "/error") |
||||
public Map<String, Object> handle(HttpServletRequest request) { |
||||
Map<String, Object> map = new HashMap<>(); |
||||
map.put("status", request.getAttribute("jakarta.servlet.error.status_code")); |
||||
map.put("reason", request.getAttribute("jakarta.servlet.error.message")); |
||||
return map; |
||||
} |
||||
} |
||||
// end::snippet[]
|
||||
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
/* |
||||
* Copyright 2002-2025 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.webmvc.mvcservlet.mvcanncustomerservletcontainererrorpage |
||||
|
||||
import jakarta.servlet.http.HttpServletRequest |
||||
import org.springframework.web.bind.annotation.RequestMapping |
||||
import org.springframework.web.bind.annotation.RestController |
||||
|
||||
// tag::snippet[] |
||||
@RestController |
||||
class ErrorController { |
||||
|
||||
@RequestMapping(path = ["/error"]) |
||||
fun handle(request: HttpServletRequest): Map<String, Any> { |
||||
val map = HashMap<String, Any>() |
||||
map["status"] = request.getAttribute("jakarta.servlet.error.status_code")!! |
||||
map["reason"] = request.getAttribute("jakarta.servlet.error.message")!! |
||||
return map |
||||
} |
||||
} |
||||
// end::snippet[] |
||||
Loading…
Reference in new issue