Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 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 | package org.onosproject.restconf.api; |
| 17 | |
| 18 | import javax.ws.rs.WebApplicationException; |
| 19 | import javax.ws.rs.core.Response; |
| 20 | |
| 21 | import static javax.ws.rs.core.Response.Status; |
| 22 | |
| 23 | /** |
| 24 | * Exceptions raised during RESTCONF operations. This class extends |
| 25 | * WebApplicationException. The design intention is to create a place holder |
| 26 | * for RESTCONF specific errors and to be able to add more functions as the |
| 27 | * subsystem grows. |
| 28 | */ |
| 29 | public class RestconfException extends WebApplicationException { |
| 30 | |
| 31 | // This is a randomly generated value. A WebApplicationException class is required to define it. |
| 32 | private static final long SERIAL_VERSION_UID = 3275970397584007046L; |
| 33 | |
| 34 | /** |
| 35 | * Constructs a new RESTCONF server error exception. The caller raising this |
| 36 | * exception may pass in a HTTP error status code and an error message. The |
| 37 | * error code will be displayed to the RESTCONF client as part of the |
| 38 | * response from the RESTCONF server. The error message is a string which |
| 39 | * may be saved in a log file and may be later retrieved by the |
| 40 | * getMessage() method. |
| 41 | * |
| 42 | * @param message the detailed error message |
| 43 | * @param status HTTP error status |
| 44 | * @throws IllegalArgumentException in case the status code is null or is not from |
| 45 | * javax.ws.rs.core.Response.Status.Family |
| 46 | * status code family |
| 47 | */ |
| 48 | public RestconfException(String message, Status status) { |
| 49 | super(message, null, Response.status(status).build()); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Constructs a new RESTCONF server error exception. The caller raising |
| 54 | * this exception may pass in the numerical value of a HTTP error |
| 55 | * status code, The error code will be displayed to the RESTCONF client |
| 56 | * as a response from the RESTCONF server. |
| 57 | * |
| 58 | * @param status HTTP error status |
| 59 | * @throws IllegalArgumentException in case the status code is not a valid |
| 60 | * HTTP status code or if it is not from the |
| 61 | * javax.ws.rs.core.Response.Status.Family |
| 62 | * status code family |
| 63 | */ |
| 64 | public RestconfException(int status) { |
| 65 | super((Throwable) null, Response.status(status).build()); |
| 66 | } |
| 67 | } |