Skip to content

Commit

Permalink
adds msgCode to MessageException
Browse files Browse the repository at this point in the history
  • Loading branch information
Clay-Ferguson committed Dec 11, 2024
1 parent e22a029 commit a37f38b
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/main/java/quanta/exception/MessageException.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,26 @@

// Exception class where we want the message to be displayed to the user
public class MessageException extends RuntimeEx {
private String msgCode;

public MessageException(String msg) {
super(msg);
}

public MessageException(String msg, String msgCode) {
super(msg);
this.msgCode = msgCode;
}

public int getCode() {
return HttpServletResponse.SC_SEE_OTHER;
}

public String getMsgCode() {
return msgCode;
}

public void setMsgCode(String msgCode) {
this.msgCode = msgCode;
}
}
6 changes: 5 additions & 1 deletion src/main/java/quanta/exception/NoAgentException.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
// Exception class where we want the message to be displayed to the user
public class NoAgentException extends MessageException {

// NOTE: warning. This string is hardcoded into the frontend too for now.
static final String MSG_CODE = "NO_AGENT";

public NoAgentException() {
super("No AI service found from parent nodes. Fix this by selecting a higher level node and using `Menu -> AI -> Configure Agent`");
super("No AI service found from parent nodes. Fix this by selecting a higher level node and using `Menu -> AI -> Configure Agent`",
MSG_CODE);
}
}
4 changes: 3 additions & 1 deletion src/main/java/quanta/model/client/SystemConfig.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package quanta.model.client;

public class SystemConfig {
// Holds the AI Config node id
// Holds the AI Config node id (todo-0: is this still used? and are ANY of the AI config fields
// still used?)
private String agentNodeId;

private String prompt; // ex: "you are a helpful assistant"
private String foldersToInclude; // newline delimited list of file paths
private String foldersToExclude; // newline delimited list of file paths
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/quanta/rest/response/base/ResponseBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class ResponseBase {
private String message;
private String stackTrace;
private Integer code;
private String msgCode;

// For diagnostic purposes we can put an info string about which replica on the docker swarm
// was responsible for processing the request.
Expand Down Expand Up @@ -65,4 +66,12 @@ public String getStackTrace() {
public void setStackTrace(String stackTrace) {
this.stackTrace = stackTrace;
}

public String getMsgCode() {
return msgCode;
}

public void setMsgCode(String msgCode) {
this.msgCode = msgCode;
}
}
5 changes: 5 additions & 0 deletions src/main/java/quanta/util/CallProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import jakarta.servlet.http.HttpSession;
import quanta.AppServer;
import quanta.config.ServiceBase;
import quanta.exception.MessageException;
import quanta.exception.base.RuntimeEx;
import quanta.perf.PerfEvent;
import quanta.rest.request.base.RequestBase;
Expand Down Expand Up @@ -127,6 +128,10 @@ private void setResponse(ResponseBase orb, int code, Exception e) {
String stack = ExceptionUtils.getStackTrace(e);
log.debug("ERROR: " + stack);
orb.setStackTrace(stack);

if (e instanceof MessageException _e) {
orb.setMsgCode(_e.getMsgCode());
}
}

if (logResponses) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/public/src/JavaIntf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,7 @@ export interface ResponseBase {
message: string;
stackTrace: string;
code: number;
msgCode: string;
replica: string;
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/public/src/RpcUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,13 @@ export class RpcUtil {

if (res.code === C.RESPONSE_CODE_SEE_OTHER) {
console.error("Warning: " + postName + " RES: " + S.util.prettyPrint(res));
// if (res.msgCode === "NO_AGENT") {
// NOTE: to resolve this we could create a 'getNode()' method on the server to get the user's
// AccountNode, and then open ConfigurAIDlg with that node. (todo-1)
// }
// else {
S.util.showMessage(res.message, "Message");
// }
return;
}

Expand Down

0 comments on commit a37f38b

Please sign in to comment.