Skip to content

Commit d8b2a80

Browse files
fix: handle invalid credentials err while uploading file in form
1 parent 6a4124f commit d8b2a80

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

apps/OpenSign/src/pages/Form.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ const Forms = (props) => {
7474
const [fileload, setfileload] = useState(false);
7575
const [percentage, setpercentage] = useState(0);
7676
const [isReset, setIsReset] = useState(false);
77-
const [isAlert, setIsAlert] = useState(false);
77+
const [isAlert, setIsAlert] = useState({ type: "success", message: "" });
7878
const [isSubmit, setIsSubmit] = useState(false);
79-
const [isErr, setIsErr] = useState("");
8079
const [isPassword, setIsPassword] = useState(false);
8180
const [isDecrypting, setIsDecrypting] = useState(false);
8281
const [isCorrectPass, setIsCorrectPass] = useState(true);
@@ -389,6 +388,10 @@ const Forms = (props) => {
389388
return { url: savetos3.url };
390389
} catch (err) {
391390
console.log("err in save to customfile", err);
391+
alert(err?.message);
392+
if (inputFileRef.current) {
393+
inputFileRef.current.value = ""; // Set file input value to empty string
394+
}
392395
return { url: "" };
393396
}
394397
};
@@ -600,13 +603,17 @@ const Forms = (props) => {
600603
setFileUpload("");
601604
setpercentage(0);
602605
navigate(`/${props?.redirectRoute}/${res.id}`);
606+
setIsAlert((obj) => ({
607+
...obj,
608+
type: "success",
609+
message: `${props.msgVar} created successfully!`
610+
}));
603611
}
604612
} catch (err) {
605613
console.log("err ", err);
606-
setIsErr(true);
614+
setIsAlert({ type: "danger", message: t("something-went-wrong-mssg") });
607615
} finally {
608-
setIsAlert(true);
609-
setTimeout(() => setIsAlert(false), 1000);
616+
setTimeout(() => setIsAlert({ type: "success", message: "" }), 1000);
610617
setIsSubmit(false);
611618
}
612619
} else {
@@ -768,13 +775,7 @@ const Forms = (props) => {
768775
return (
769776
<div className="shadow-md rounded-box my-[2px] p-3 bg-base-100 text-base-content">
770777
<Title title={props?.title} />
771-
{isAlert && (
772-
<Alert type={isErr ? "danger" : "success"}>
773-
{isErr
774-
? t("something-went-wrong-mssg")
775-
: `${props.msgVar} created successfully!`}
776-
</Alert>
777-
)}
778+
{isAlert?.message && <Alert type={isAlert.type}>{isAlert.message}</Alert>}
778779
{isSubmit ? (
779780
<div className="h-[300px] flex justify-center items-center">
780781
<Loader />

apps/OpenSignServer/cloud/parsefunction/saveToFileAdapter.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ export default async function saveToFileAdapter(request) {
4444
return { url: presignedUrl };
4545
} catch (err) {
4646
console.error('Error generate presigned url:', err);
47-
throw new Parse.Error(400, 'Something went wrong.');
47+
const msg = 'Fileadapter credentials are invalid.';
48+
throw new Parse.Error(400, msg);
4849
}
4950
} else {
5051
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'S3 credentials not found.');

apps/OpenSignServer/cloud/parsefunction/uploadFiletoS3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async function uploadFileToS3(buffer, fileName, mimeType, adapter) {
3030
const presignedUrl = await getSignedUrl(client, getCommand, { expiresIn: 900 }); // URL expiration time in seconds (e.g., 15 min)
3131
return presignedUrl;
3232
} catch (error) {
33-
console.error('Error uploading file to aws:', error);
33+
console.error('Error uploading file to aws:', error?.message);
3434
throw error;
3535
}
3636
}

0 commit comments

Comments
 (0)