blob: 8e2edfd1cb04288b83eb059a93b7ab6098017470 [file] [log] [blame]
andrewsbrown43b96302015-03-17 21:51:43 +01001/*
2 * jndn-management
3 * Copyright (c) 2015, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU Lesser General Public License,
7 * version 3, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT ANY
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
12 * more details.
13 */
Alexander Afanasyeva8bc0d82016-01-25 17:25:30 -080014
andrewsbrown43b96302015-03-17 21:51:43 +010015package com.intel.jndn.management;
16
Alexander Afanasyev499aced2016-02-17 19:32:37 -080017import net.named_data.jndn.ControlResponse;
18
andrewsbrown43b96302015-03-17 21:51:43 +010019
20/**
21 * Represent a failure to correctly manage the NDN Forwarding Daemon (NFD).
22 * Inspect this object with getCause() to see why the management operation
23 * failed.
24 *
25 * @author Andrew Brown <andrew.brown@intel.com>
26 */
27public class ManagementException extends Exception {
andrewsbrown43b96302015-03-17 21:51:43 +010028 /**
Alexander Afanasyeve36e1af2016-02-19 18:06:05 -080029 * Constructor from the message.
30 * @param message Error message
andrewsbrown43b96302015-03-17 21:51:43 +010031 */
Alexander Afanasyeve36e1af2016-02-19 18:06:05 -080032 public ManagementException(final String message) {
andrewsbrown43b96302015-03-17 21:51:43 +010033 super(message);
34 }
35
36 /**
Alexander Afanasyeve36e1af2016-02-19 18:06:05 -080037 * Constructor from the message and the cause.
38 * @param message Error message
39 * @param cause Chained exception
andrewsbrown43b96302015-03-17 21:51:43 +010040 */
Alexander Afanasyeve36e1af2016-02-19 18:06:05 -080041 public ManagementException(final String message, final Throwable cause) {
andrewsbrown43b96302015-03-17 21:51:43 +010042 super(message, cause);
43 }
44
45 /**
Alexander Afanasyeve36e1af2016-02-19 18:06:05 -080046 * Create exception from NFD's ControlResponse.
47 * @param response ControlResponse from which to use status code and status text
48 * @return new instance of ManagementException
andrewsbrown43b96302015-03-17 21:51:43 +010049 */
Alexander Afanasyeve36e1af2016-02-19 18:06:05 -080050 public static ManagementException fromResponse(final ControlResponse response) {
andrewsbrown43b96302015-03-17 21:51:43 +010051 String message = "Action failed, forwarder returned: " + response.getStatusCode() + " " + response.getStatusText();
52 return new ManagementException(message);
53 }
54}