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.
|
||||
*
|
||||
* @author GideonLeGrange
|
||||
*/
|
||||
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() {
|
||||
return tag;
|
||||
}
|
||||
|
|
@ -23,12 +29,15 @@ public class ApiCommandException extends MikrotikApiException {
|
|||
super(msg, err);
|
||||
}
|
||||
|
||||
public int getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
ApiCommandException(Error err) {
|
||||
super(err.getMessage());
|
||||
tag = err.getTag();
|
||||
category = err.getCategory();
|
||||
}
|
||||
|
||||
private String tag = null;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -248,7 +248,7 @@ public final class ApiConnectionImpl extends ApiConnection {
|
|||
} catch (ApiCommandException ex) {
|
||||
String tag = ex.getTag();
|
||||
if (tag != null) {
|
||||
res = new Error(tag, ex.getMessage());
|
||||
res = new Error(tag, ex.getMessage(), ex.getCategory());
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -415,6 +415,9 @@ public final class ApiConnectionImpl extends ApiConnection {
|
|||
} else if (line.startsWith("=message=")) {
|
||||
err.setMessage(line.split("=", 3)[2]);
|
||||
}
|
||||
else if (line.startsWith("=category=")) {
|
||||
err.setCategory(Integer.parseInt(line.split("=", 3)[2]));
|
||||
}
|
||||
if (hasNextLine()) {
|
||||
nextLine();
|
||||
} 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).
|
||||
*
|
||||
* @author GideonLeGrange
|
||||
*/
|
||||
class Error extends Response {
|
||||
|
||||
Error(String tag, String message) {
|
||||
private String message;
|
||||
private int category;
|
||||
|
||||
Error(String tag, String message, int category) {
|
||||
super(tag);
|
||||
this.message = message;
|
||||
}
|
||||
|
|
@ -18,11 +22,16 @@ class Error extends Response {
|
|||
String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
private String message;
|
||||
|
||||
int getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
void setCategory(int category) {
|
||||
this.category = category;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue