Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion backend/platform_settings_v2/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ class FoundActiveKey(APIException):

class ActiveKeyNotFound(APIException):
status_code = 404
default_detail = "At least one active platform key should be available"
default_detail = (
"An active platform key is required to perform this action. "
"Configure one in [Platform Keys](/settings/platform) under Settings."
)


class InvalidRequest(APIException):
Expand Down
5 changes: 0 additions & 5 deletions backend/workflow_manager/workflow_v2/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ class InvalidRequest(APIException):
default_detail = "Invalid Request"


class MissingEnvException(APIException):
status_code = 500
default_detail = "At least one active platform key should be available."


class InternalException(APIException):
"""Internal Error.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Typography } from "antd";
import PropTypes from "prop-types";
import { useMemo } from "react";
import { Link as RouterLink } from "react-router-dom";

const { Text, Link, Paragraph } = Typography;

Expand Down Expand Up @@ -48,12 +49,17 @@ const CustomMarkdown = ({
{content}
</Text>
);
case "link":
case "link": {
const isInternal = url?.startsWith("/");
if (isInternal) {
return <RouterLink to={url}>{content}</RouterLink>;
}
return (
<Link href={url} target="_blank" rel="noopener noreferrer">
{content}
</Link>
);
}
case "newline":
return renderNewLines ? <br /> : "\n";
default:
Expand Down
97 changes: 43 additions & 54 deletions frontend/src/hooks/useExceptionHandler.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
import PropTypes from "prop-types";
import { useNavigate } from "react-router-dom";

import { useSessionStore } from "../store/session-store.js";

const useExceptionHandler = () => {
const navigate = useNavigate();
const { sessionDetails } = useSessionStore();

// Resolves relative markdown links [text](/path) to [text](/{orgName}/path)
const enrichMarkdownLinks = (message) => {
if (typeof message !== "string") {
return message;
}
const orgName = sessionDetails?.orgName;
if (!orgName) {
return message;
}
return message.replace(

Check warning on line 19 in frontend/src/hooks/useExceptionHandler.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `String#replaceAll()` over `String#replace()`.

See more on https://sonarcloud.io/project/issues?id=Zipstack_unstract&issues=AZ0-IWk97c7kP5Facj7D&open=AZ0-IWk97c7kP5Facj7D&pullRequest=1878
/\[([^\]]+)\]\(\/((?!\/)[^)]+)\)/g,
(_, text, path) => `[${text}](/${orgName}/${path})`,
);
};

const buildAlert = (content, title, duration) => ({
type: "error",
content: enrichMarkdownLinks(content),
title,
duration,
});

const handleException = (
err,
errMessage = "Something went wrong",
Expand All @@ -11,27 +37,16 @@
duration = 0,
) => {
if (!err) {
return {
type: "error",
content: errMessage,
title: title,
duration: duration,
};
return buildAlert(errMessage, title, duration);
}
if (err.code === "ERR_NETWORK" && !navigator.onLine) {
return {
type: "error",
content: "Please check your internet connection.",
title: title,
duration: duration,
};
return buildAlert(
"Please check your internet connection.",
title,
duration,
);
} else if (err.code === "ERR_CANCELED") {
return {
type: "error",
content: "Request has been canceled.",
title: title,
duration: duration,
};
return buildAlert("Request has been canceled.", title, duration);
}

if (err?.response?.data) {
Expand All @@ -43,12 +58,7 @@
responseData.error || responseData.detail || responseData.message;

if (commonErrorMessage) {
return {
title: title,
type: "error",
content: commonErrorMessage,
duration: duration,
};
return buildAlert(commonErrorMessage, title, duration);
}

// Then handle specific error types
Expand Down Expand Up @@ -81,45 +91,24 @@
.join("\n");
}
}
return {
title: title,
type: "error",
content: errorMessage,
duration: duration,
};
return buildAlert(errorMessage, title, duration);
}
break;
case "subscription_error":
navigate("/subscription-expired");
return {
title: title,
type: "error",
content: errors,
duration: duration,
};
return buildAlert(errors, title, duration);
case "client_error":
case "server_error":
return {
title: title,
type: "error",
content: errors?.[0]?.detail ? errors[0].detail : errMessage,
duration: duration,
};
return buildAlert(
errors?.[0]?.detail ? errors[0].detail : errMessage,
title,
duration,
);
default:
return {
title: title,
type: "error",
content: errMessage,
duration: duration,
};
return buildAlert(errMessage, title, duration);
}
} else {
return {
title: title,
type: "error",
content: errMessage,
duration: duration,
};
return buildAlert(errMessage, title, duration);
}
};

Expand Down
Loading