View Javadoc
1   /*
2    * Copyright 2019 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.bremersee.exception;
18  
19  import java.util.List;
20  import javax.validation.constraints.NotNull;
21  import org.bremersee.exception.model.RestApiException;
22  import org.springframework.http.HttpStatus;
23  import org.springframework.lang.Nullable;
24  import org.springframework.validation.annotation.Validated;
25  
26  /**
27   * Maps the error response into a {@link RestApiException}.
28   *
29   * @author Christian Bremer
30   */
31  @Validated
32  public interface RestApiExceptionMapper {
33  
34    /**
35     * Gets the paths this mapper is responsible for.
36     *
37     * @return the list of paths (typically ant paths)
38     */
39    @NotNull List<String> getApiPaths();
40  
41    /**
42     * Build the exception model from the exception, the requested path and an handler. Typically the handler is of type
43     * {@link org.springframework.web.method.HandlerMethod}.
44     *
45     * @param exception the exception (required)
46     * @param requestPath the requested path (optional)
47     * @param handler the handler (optional)
48     * @return the rest api exception
49     */
50    @NotNull RestApiException build(
51        @NotNull Throwable exception,
52        @Nullable String requestPath,
53        @Nullable Object handler);
54  
55    /**
56     * Detects the http status.
57     *
58     * @param exception the exception (required)
59     * @param handler the handler (optional)
60     * @return the http status
61     */
62    @NotNull
63    HttpStatus detectHttpStatus(@NotNull Throwable exception, @Nullable Object handler);
64  }