Added support for error category to ApiCommandException which was weirdly missing. Not complete
This commit is contained in:
parent
1f31a6f3b5
commit
8fa8711ec5
|
|
@ -4,13 +4,19 @@ import me.legrange.mikrotik.MikrotikApiException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thrown when the Mikrotik returns an error when receiving our command.
|
* Thrown when the Mikrotik returns an error when receiving our command.
|
||||||
|
*
|
||||||
* @author GideonLeGrange
|
* @author GideonLeGrange
|
||||||
*/
|
*/
|
||||||
public class ApiCommandException extends MikrotikApiException {
|
public class ApiCommandException extends MikrotikApiException {
|
||||||
|
|
||||||
|
private String tag = null;
|
||||||
|
private int category = 0;
|
||||||
|
|
||||||
/** return the tag associated with this exception, if there is one
|
/**
|
||||||
* @return the tag associated with this exception. Null if there is no tag*/
|
* return the tag associated with this exception, if there is one
|
||||||
|
*
|
||||||
|
* @return the tag associated with this exception. Null if there is no tag
|
||||||
|
*/
|
||||||
public String getTag() {
|
public String getTag() {
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
@ -23,12 +29,15 @@ public class ApiCommandException extends MikrotikApiException {
|
||||||
super(msg, err);
|
super(msg, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getCategory() {
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
|
||||||
ApiCommandException(Error err) {
|
ApiCommandException(Error err) {
|
||||||
super(err.getMessage());
|
super(err.getMessage());
|
||||||
tag = err.getTag();
|
tag = err.getTag();
|
||||||
|
category = err.getCategory();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String tag = null;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -248,7 +248,7 @@ public final class ApiConnectionImpl extends ApiConnection {
|
||||||
} catch (ApiCommandException ex) {
|
} catch (ApiCommandException ex) {
|
||||||
String tag = ex.getTag();
|
String tag = ex.getTag();
|
||||||
if (tag != null) {
|
if (tag != null) {
|
||||||
res = new Error(tag, ex.getMessage());
|
res = new Error(tag, ex.getMessage(), ex.getCategory());
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -415,6 +415,9 @@ public final class ApiConnectionImpl extends ApiConnection {
|
||||||
} else if (line.startsWith("=message=")) {
|
} else if (line.startsWith("=message=")) {
|
||||||
err.setMessage(line.split("=", 3)[2]);
|
err.setMessage(line.split("=", 3)[2]);
|
||||||
}
|
}
|
||||||
|
else if (line.startsWith("=category=")) {
|
||||||
|
err.setCategory(Integer.parseInt(line.split("=", 3)[2]));
|
||||||
|
}
|
||||||
if (hasNextLine()) {
|
if (hasNextLine()) {
|
||||||
nextLine();
|
nextLine();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,15 @@ package me.legrange.mikrotik.impl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to encapsulate API error information. We need to pass both the message and the tag (if one was used).
|
* Used to encapsulate API error information. We need to pass both the message and the tag (if one was used).
|
||||||
|
*
|
||||||
* @author GideonLeGrange
|
* @author GideonLeGrange
|
||||||
*/
|
*/
|
||||||
class Error extends Response {
|
class Error extends Response {
|
||||||
|
|
||||||
Error(String tag, String message) {
|
private String message;
|
||||||
|
private int category;
|
||||||
|
|
||||||
|
Error(String tag, String message, int category) {
|
||||||
super(tag);
|
super(tag);
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
@ -18,11 +22,16 @@ class Error extends Response {
|
||||||
String getMessage() {
|
String getMessage() {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMessage(String message) {
|
void setMessage(String message) {
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String message;
|
int getCategory() {
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setCategory(int category) {
|
||||||
|
this.category = category;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue