1 /*
2 * Copyright 2012-2025 CodeLibs Project and the Others.
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,
13 * either express or implied. See the License for the specific language
14 * governing permissions and limitations under the License.
15 */
16 package org.codelibs.fess.exception;
17
18 /**
19 * Exception thrown when web API operations encounter errors.
20 * This exception includes an HTTP status code to indicate the nature of the error.
21 */
22 public class WebApiException extends FessSystemException {
23
24 private static final long serialVersionUID = 1L;
25
26 /**
27 * The HTTP status code associated with this exception.
28 */
29 private final int statusCode;
30
31 /**
32 * Gets the HTTP status code associated with this exception.
33 *
34 * @return The HTTP status code
35 */
36 public int getStatusCode() {
37 return statusCode;
38 }
39
40 /**
41 * Constructs a WebApiException with the specified status code, message, and cause.
42 *
43 * @param statusCode The HTTP status code
44 * @param message The detail message
45 * @param cause The cause of this exception
46 */
47 public WebApiException(final int statusCode, final String message, final Throwable cause) {
48 super(message, cause);
49 this.statusCode = statusCode;
50 }
51
52 /**
53 * Constructs a WebApiException with the specified status code and message.
54 *
55 * @param statusCode The HTTP status code
56 * @param message The detail message
57 */
58 public WebApiException(final int statusCode, final String message) {
59 super(message);
60 this.statusCode = statusCode;
61 }
62
63 /**
64 * Constructs a WebApiException with the specified status code and exception.
65 *
66 * @param statusCode The HTTP status code
67 * @param e The exception that caused this WebApiException
68 */
69 public WebApiException(final int statusCode, final Exception e) {
70 this(statusCode, e.getMessage(), e);
71 }
72 }