mirror of
https://github.com/logos-storage/logos-storage-frontend.git
synced 2026-01-02 13:23:09 +00:00
Modified error messages for post requests
This commit is contained in:
parent
c3078124ff
commit
52217354f0
@ -8,4 +8,4 @@ services:
|
||||
ports:
|
||||
- "3000:80"
|
||||
environment:
|
||||
- codex_url=${codex_url:-http://kubernetes.docker.internal:30003}
|
||||
- codex_url=${codex_url:-http://kubernetes.docker.internal:30001}
|
||||
|
||||
@ -7,6 +7,7 @@ function DownloadTab() {
|
||||
const { ftdCid, setFtdCid, nodeInfo } = useDexyStore();
|
||||
|
||||
const [filename, setFilename] = useState("file");
|
||||
const [error, setError] = useState("");
|
||||
|
||||
function download(cid: string) {
|
||||
console.log(filename);
|
||||
@ -22,7 +23,10 @@ function DownloadTab() {
|
||||
{},
|
||||
}
|
||||
)
|
||||
.then((response) => response.blob())
|
||||
.then((response) =>
|
||||
{
|
||||
if (response.status === 200) {
|
||||
response.blob()
|
||||
.then((blob) => {
|
||||
const url = window.URL.createObjectURL(new Blob([blob]));
|
||||
const link = document.createElement("a");
|
||||
@ -31,10 +35,25 @@ function DownloadTab() {
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
link.parentNode?.removeChild(link);
|
||||
})
|
||||
}
|
||||
else {
|
||||
response.text().then((text) => {
|
||||
setError(text);
|
||||
}).catch((error) => {
|
||||
console.error("Error reading response body:", error);
|
||||
setError("Failed to read response body");
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error downloading file:", error);
|
||||
setError("Failed to download file");
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<DownloadTabWrapper>
|
||||
<input
|
||||
type="text"
|
||||
@ -52,6 +71,12 @@ function DownloadTab() {
|
||||
/>
|
||||
<button onClick={() => download(ftdCid)}>Download</button>
|
||||
</DownloadTabWrapper>
|
||||
{error && (
|
||||
<p style={{ color: "red", marginTop: "10px", textAlign: "center" }}>
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -14,6 +14,7 @@ function UploadTab() {
|
||||
const { uploads, setUploads, nodeInfo } = useDexyStore();
|
||||
var files = useRef<UploadedItemModel[]>(uploads);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
function getDatas() {
|
||||
fetch(`/api/codex/v1/data`, {
|
||||
@ -90,12 +91,17 @@ function UploadTab() {
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
if (response.status === 200) {
|
||||
newCid = response.data;
|
||||
getDatas();
|
||||
} else {
|
||||
setError("Upload failed");
|
||||
}
|
||||
});
|
||||
console.log("filesCopy failed");
|
||||
} catch (error) {
|
||||
console.error("Error uploading file: ", error);
|
||||
setError("Upload failed");
|
||||
}
|
||||
console.log(cid + acceptedFiles[i].name);
|
||||
resolve("done");
|
||||
@ -108,6 +114,7 @@ function UploadTab() {
|
||||
const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop });
|
||||
|
||||
return (
|
||||
<>
|
||||
<UploadTabWrapper>
|
||||
<div
|
||||
id="dropzone"
|
||||
@ -134,6 +141,12 @@ function UploadTab() {
|
||||
))}
|
||||
</div>
|
||||
</UploadTabWrapper>
|
||||
{error && (
|
||||
<p style={{ color: "red", marginTop: "10px", textAlign: "center" }}>
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@ function OfferStorage() {
|
||||
const [minPrice, setMinPrice,] = useState("file");
|
||||
const [maxCollateral, setMaxCollateral,] = useState("file");
|
||||
const [expiry, setExpiry,] = useState("file");
|
||||
const [error, setError] = useState("");
|
||||
|
||||
|
||||
function upload(cid: string) {
|
||||
@ -36,14 +37,25 @@ function OfferStorage() {
|
||||
// create a popup in the browser to show if the upload was successful
|
||||
.then((response) => {
|
||||
if (response.status === 200) {
|
||||
alert("Upload successful!");
|
||||
alert("Successfully created storage offer!");
|
||||
setError("");
|
||||
} else {
|
||||
alert("Upload failed!");
|
||||
response.text().then((text) => {
|
||||
setError(text);
|
||||
}).catch((error) => {
|
||||
console.error("Error reading response body:", error);
|
||||
setError("Failed to read response body");
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error creating storage offer:", error);
|
||||
setError("Failed to create storage offer");
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<OfferStorageWrapper>
|
||||
<input
|
||||
type="text"
|
||||
@ -83,8 +95,14 @@ function OfferStorage() {
|
||||
placeholder="Expiry"
|
||||
onChange={(e) => setExpiry(e.target.value)}
|
||||
/>
|
||||
<button onClick={() => upload(ftdCid)}>Download</button>
|
||||
<button onClick={() => upload(ftdCid)}>Create</button>
|
||||
</OfferStorageWrapper>
|
||||
{error && (
|
||||
<p style={{ color: "red", marginTop: "10px", textAlign: "center" }}>
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -10,6 +10,7 @@ function CreateTab() {
|
||||
const [duration, setDuration,] = useState("file");
|
||||
const [proofProbability, setProofProbability,] = useState("file");
|
||||
const [collateral, setCollateral,] = useState("file");
|
||||
const [error, setError] = useState("");
|
||||
|
||||
|
||||
function upload(cid: string) {
|
||||
@ -34,14 +35,25 @@ function CreateTab() {
|
||||
// create a popup in the browser to show if the upload was successful
|
||||
.then((response) => {
|
||||
if (response.status === 200) {
|
||||
alert("Upload successful!");
|
||||
alert("Successfully created storage offer!");
|
||||
setError("");
|
||||
} else {
|
||||
alert("Upload failed!");
|
||||
response.text().then((text) => {
|
||||
setError(text);
|
||||
}).catch((error) => {
|
||||
console.error("Error reading response body:", error);
|
||||
setError("Failed to read response body");
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error creating storage offer:", error);
|
||||
setError("Failed to create storage offer");
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<CreateTabWrapper>
|
||||
<input
|
||||
type="text"
|
||||
@ -77,6 +89,12 @@ function CreateTab() {
|
||||
/>
|
||||
<button onClick={() => upload(ftdCid)}>Download</button>
|
||||
</CreateTabWrapper>
|
||||
{error && (
|
||||
<p style={{ color: "red", marginTop: "10px", textAlign: "center" }}>
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user