Added more error message handlers to SDK

This commit is contained in:
frikky
2022-10-22 22:56:05 +02:00
parent 558b47b7dd
commit cbaf4ace92
4 changed files with 75 additions and 59 deletions
+4 -5
View File
@@ -1433,7 +1433,7 @@ class AppBase:
"execution_id": self.current_execution_id "execution_id": self.current_execution_id
} }
self.logger.info("[DEBUG] Before FULLEXEC stream result") self.logger.info("[ERROR] Before FULLEXEC stream result")
ret = requests.post( ret = requests.post(
"%s/api/v1/streams/results" % (self.base_url), "%s/api/v1/streams/results" % (self.base_url),
headers=headers, headers=headers,
@@ -1444,8 +1444,7 @@ class AppBase:
fullexecution = ret.json() fullexecution = ret.json()
else: else:
try: try:
self.logger.info("[DEBUG] Error: Data: ", ret.json()) self.logger.info("[ERROR] Error in app with status code for results. Crashing because results can't be handled. Status: %d" % ret.status_code)
self.logger.info("[DEBUG] Error with status code for results. Crashing because ACTION_RESULTS or WORKFLOW_VARIABLE can't be handled. Status: %d" % ret.status_code)
except json.decoder.JSONDecodeError: except json.decoder.JSONDecodeError:
pass pass
@@ -1457,7 +1456,7 @@ class AppBase:
self.send_result(self.action_result, headers, stream_path) self.send_result(self.action_result, headers, stream_path)
return return
except requests.exceptions.ConnectionError as e: except requests.exceptions.ConnectionError as e:
self.logger.info("[DEBUG] FullExec Connectionerror: %s" % e) self.logger.info("[ERROR] FullExec Connectionerror: %s" % e)
self.action_result["result"] = json.dumps({ self.action_result["result"] = json.dumps({
"success": False, "success": False,
"reason": f"Connection error during startup: {e}" "reason": f"Connection error during startup: {e}"
@@ -1470,7 +1469,7 @@ class AppBase:
try: try:
fullexecution = json.loads(self.full_execution) fullexecution = json.loads(self.full_execution)
except json.decoder.JSONDecodeError as e: except json.decoder.JSONDecodeError as e:
self.logger.info("[WARNING] Json decode execution error: %s" % e) self.logger.info("[ERROR] Json decode execution error: %s" % e)
self.action_result["result"] = "Json error during startup: %s" % e self.action_result["result"] = "Json error during startup: %s" % e
self.send_result(self.action_result, headers, stream_path) self.send_result(self.action_result, headers, stream_path)
return return
+3 -4
View File
@@ -2,8 +2,7 @@ module main
go 1.16 go 1.16
replace github.com/shuffle/shuffle-shared => ../../../shuffle-shared //replace github.com/shuffle/shuffle-shared => ../../../shuffle-shared
//replace github.com/frikky/kin-openapi => ../../../../git/kin-openapi //replace github.com/frikky/kin-openapi => ../../../../git/kin-openapi
//replace github.com/frikky/go-elasticsearch => ../../../../git/go-elasticsearch //replace github.com/frikky/go-elasticsearch => ../../../../git/go-elasticsearch
@@ -15,7 +14,7 @@ require (
github.com/basgys/goxml2json v1.1.0 github.com/basgys/goxml2json v1.1.0
github.com/carlescere/scheduler v0.0.0-20170109141437-ee74d2f83d82 github.com/carlescere/scheduler v0.0.0-20170109141437-ee74d2f83d82
github.com/docker/docker v20.10.12+incompatible github.com/docker/docker v20.10.12+incompatible
github.com/frikky/kin-openapi v0.41.0 github.com/frikky/kin-openapi v0.42.0
github.com/fsouza/go-dockerclient v1.7.7 github.com/fsouza/go-dockerclient v1.7.7
github.com/ghodss/yaml v1.0.0 github.com/ghodss/yaml v1.0.0
github.com/go-git/go-billy/v5 v5.3.1 github.com/go-git/go-billy/v5 v5.3.1
@@ -24,7 +23,7 @@ require (
github.com/h2non/filetype v1.1.3 github.com/h2non/filetype v1.1.3
github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20170819232839-0fbfe93532da // indirect github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20170819232839-0fbfe93532da // indirect
github.com/satori/go.uuid v1.2.0 github.com/satori/go.uuid v1.2.0
github.com/shuffle/shuffle-shared v0.2.87 github.com/shuffle/shuffle-shared v0.3.5
go4.org v0.0.0-20201209231011-d4a079459e60 // indirect go4.org v0.0.0-20201209231011-d4a079459e60 // indirect
golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce
google.golang.org/api v0.65.0 google.golang.org/api v0.65.0
+40 -35
View File
@@ -34,8 +34,17 @@ import {
AttachFile as AttachFileIcon, AttachFile as AttachFileIcon,
Apps as AppsIcon, Apps as AppsIcon,
ErrorOutline as ErrorOutlineIcon, ErrorOutline as ErrorOutlineIcon,
AddAPhoto as AddAPhotoIcon,
AddAPhotoOutlined as AddAPhotoOutlinedIcon,
ZoomInOutlined as ZoomInOutlinedIcon,
ZoomOutOutlined as ZoomOutOutlinedIcon,
Loop as LoopIcon,
} from "@material-ui/icons"; } from "@material-ui/icons";
import {
AddPhotoAlternate as AddPhotoAlternateIcon,
} from '@mui/icons-material';
import { v4 as uuidv4 } from "uuid"; import { v4 as uuidv4 } from "uuid";
import { Link, useParams } from "react-router-dom"; import { Link, useParams } from "react-router-dom";
import YAML from "yaml"; import YAML from "yaml";
@@ -44,12 +53,6 @@ import { useAlert } from "react-alert";
import words from "shellwords"; import words from "shellwords";
import AvatarEditor from "react-avatar-editor"; import AvatarEditor from "react-avatar-editor";
import AddAPhotoIcon from "@material-ui/icons/AddAPhoto";
import AddAPhotoOutlinedIcon from "@material-ui/icons/AddAPhotoOutlined";
import ZoomInOutlinedIcon from "@material-ui/icons/ZoomInOutlined";
import ZoomOutOutlinedIcon from "@material-ui/icons/ZoomOutOutlined";
import LoopIcon from "@material-ui/icons/Loop";
import AddPhotoAlternateIcon from "@material-ui/icons/AddPhotoAlternate";
const surfaceColor = "#27292D"; const surfaceColor = "#27292D";
const inputColor = "#383B40"; const inputColor = "#383B40";
@@ -344,14 +347,14 @@ const AppCreator = (defaultprops) => {
useEffect(() => { useEffect(() => {
if (window.location.pathname.includes("apps/edit")) { if (window.location.pathname.includes("apps/edit")) {
setIsEditing(true); setIsEditing(true);
handleEditApp(); handleEditApp(props.match.params.appid);
} else { } else {
checkQuery(); checkQuery();
} }
}, []); }, []);
const handleEditApp = () => { const handleEditApp = (appid) => {
fetch(globalUrl + "/api/v1/apps/" + props.match.params.appid + "/config", { fetch(globalUrl + "/api/v1/apps/" + appid + "/config", {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
@@ -390,33 +393,35 @@ const AppCreator = (defaultprops) => {
return; return;
} }
fetch(globalUrl + "/api/v1/get_openapi/" + urlParams.get("id"), { handleEditApp(urlParams.get("id"))
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
credentials: "include",
})
.then((response) => {
if (response.status !== 200) {
throw new Error("NOT 200 :O");
}
return response.json(); //fetch(globalUrl + "/api/v1/get_openapi/" + urlParams.get("id"), {
}) // method: "GET",
.then((responseJson) => { // headers: {
setIsAppLoaded(true); // "Content-Type": "application/json",
if (!responseJson.success) { // Accept: "application/json",
alert.error("Failed to verify"); // },
} else { // credentials: "include",
parseIncomingOpenapiData(responseJson); //})
} // .then((response) => {
}) // if (response.status !== 200) {
.catch((error) => { // throw new Error("NOT 200 :O");
console.log("Error: ", error.toString()); // }
alert.error(error.toString());
}); // return response.json();
// })
// .then((responseJson) => {
// setIsAppLoaded(true);
// if (!responseJson.success) {
// alert.error("Failed to verify");
// } else {
// parseIncomingOpenapiData(responseJson);
// }
// })
// .catch((error) => {
// console.log("Error: ", error.toString());
// alert.error(error.toString());
// });
}; };
const setFileFromb64 = () => { const setFileFromb64 = () => {
+28 -15
View File
@@ -39,6 +39,10 @@ import {
Delete as DeleteIcon, Delete as DeleteIcon,
} from "@material-ui/icons"; } from "@material-ui/icons";
import {
ForkRight as ForkRightIcon,
} from '@mui/icons-material';
import { useTheme } from "@material-ui/core/styles"; import { useTheme } from "@material-ui/core/styles";
import YAML from "yaml"; import YAML from "yaml";
@@ -807,9 +811,11 @@ const Apps = (props) => {
</Tooltip> </Tooltip>
) : null; ) : null;
// FIXME: Add /apps/new?id=<PUBLIC> to allow for changes of the original
// Should always reference the original ID. // Should always reference the original ID.
var editButton = //if (selectedApp.name !== undefined && selectedApp.name !== null && selectedApp.name.includes("New")) {
//}
var editButton =
selectedApp.activated && selectedApp.activated &&
selectedApp.private_id !== undefined && selectedApp.private_id !== undefined &&
selectedApp.private_id.length > 0 && selectedApp.private_id.length > 0 &&
@@ -829,21 +835,19 @@ const Apps = (props) => {
) : null; ) : null;
//var editNewButton = editButton === null ? //var editNewButton = editButton === null ?
var editNewButton = selectedApp.generated && selectedApp.activated && props.userdata.id !== selectedApp.owner ? var editNewButton = selectedApp.generated && selectedApp.activated && props.userdata.id !== selectedApp.owner && isCloud ?
isCloud ?
<Link to={activateUrl} style={{ textDecoration: "none" }}> <Link to={activateUrl} style={{ textDecoration: "none" }}>
<Tooltip title={"Edit this public app to your liking"}> <Tooltip title={"Fork and Edit this public app to your liking"}>
<Button <Button
variant="contained" variant="contained"
component="label" component="label"
color="primary" color="primary"
style={{ marginTop: 10, marginRight: 10 }} style={{ marginTop: 10, marginRight: 10 }}
> >
<EditIcon /> <ForkRightIcon />
</Button> </Button>
</Tooltip> </Tooltip>
</Link> </Link>
: null
: null : null
const activateButton = const activateButton =
@@ -879,8 +883,7 @@ const Apps = (props) => {
((selectedApp.private_id !== undefined && ((selectedApp.private_id !== undefined &&
selectedApp.private_id.length > 0 && selectedApp.private_id.length > 0 &&
selectedApp.generated) || selectedApp.generated) ||
(selectedApp.downloaded !== undefined && (selectedApp.downloaded !== undefined && selectedApp.downloaded == true) ||
selectedApp.downloaded == true) ||
!selectedApp.generated) && !selectedApp.generated) &&
activateButton === null ? ( activateButton === null ? (
<Tooltip title={"Delete app"}> <Tooltip title={"Delete app"}>
@@ -982,6 +985,10 @@ const Apps = (props) => {
const userRoles = ["you", isCloud ? "public" : "everyone"]; const userRoles = ["you", isCloud ? "public" : "everyone"];
// Admin in org or creator of app
// FIXME: Missing check for if same creator account
const canEditApp = userdata !== undefined && (userdata.admin === "true" || userdata.id === selectedApp.owner || selectedApp.owner === "" || (userdata.admin === "true" && userdata.active_org.id === selectedApp.reference_org)) || !selectedApp.generated
//fetch(globalUrl+"/api/v1/get_openapi/"+urlParams.get("id"), //fetch(globalUrl+"/api/v1/get_openapi/"+urlParams.get("id"),
var baseInfo = var baseInfo =
newAppname.length > 0 ? ( newAppname.length > 0 ? (
@@ -1086,14 +1093,20 @@ const Apps = (props) => {
) : null} ) : null}
{activateButton} {activateButton}
{editNewButton}
{(editNewButton === null && userdata !== undefined && (userdata.admin === "true" || userdata.id === selectedApp.owner || selectedApp.owner === "" )) || !selectedApp.generated ? ( { /* editNewButton === null && */ }
{canEditApp ? (
<div> <div>
{editButton} {editButton}
{downloadButton} {downloadButton}
{deleteButton} {deleteButton}
</div> </div>
) : null} ) :
<div>
{editNewButton}
</div>
}
{selectedApp.tags !== undefined && selectedApp.tags !== null ? ( {selectedApp.tags !== undefined && selectedApp.tags !== null ? (
<div <div
style={{ style={{
@@ -1119,8 +1132,8 @@ const Apps = (props) => {
})} })}
</div> </div>
) : null} ) : null}
{props.userdata !== undefined && {canEditApp
props.userdata.id === selectedApp.owner ? ( ? (
<div style={{ marginTop: 15 }}> <div style={{ marginTop: 15 }}>
{/*<p><b>ID:</b> {selectedApp.id}</p>*/} {/*<p><b>ID:</b> {selectedApp.id}</p>*/}
<b style={{ marginRight: 15 }}>Sharing </b> <b style={{ marginRight: 15 }}>Sharing </b>
@@ -1877,7 +1890,7 @@ const Apps = (props) => {
getApps(); getApps();
}, 1000); }, 1000);
} else { } else {
alert.error("Failed deleting app"); alert.error("Failed deleting app. Does it still exist?");
} }
}) })
.catch((error) => { .catch((error) => {