Differentiate between netwrok error and invalid binary error
This commit is contained in:
@@ -29,7 +29,9 @@ export const compileCode = async (activeId: number) => {
|
|||||||
const file = state.files[activeId]
|
const file = state.files[activeId]
|
||||||
try {
|
try {
|
||||||
file.containsErrors = false
|
file.containsErrors = false
|
||||||
const res = await fetch(process.env.NEXT_PUBLIC_COMPILE_API_ENDPOINT, {
|
let res: Response
|
||||||
|
try {
|
||||||
|
res = await fetch(process.env.NEXT_PUBLIC_COMPILE_API_ENDPOINT, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -48,6 +50,9 @@ export const compileCode = async (activeId: number) => {
|
|||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
throw Error("Something went wrong, check your network connection and try again!")
|
||||||
|
}
|
||||||
const json = await res.json();
|
const json = await res.json();
|
||||||
state.compiling = false;
|
state.compiling = false;
|
||||||
if (!json.success) {
|
if (!json.success) {
|
||||||
@@ -61,6 +66,7 @@ export const compileCode = async (activeId: number) => {
|
|||||||
}
|
}
|
||||||
throw errors
|
throw errors
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
// Decode base64 encoded wasm that is coming back from the endpoint
|
// Decode base64 encoded wasm that is coming back from the endpoint
|
||||||
const bufferData = await decodeBinary(json.output);
|
const bufferData = await decodeBinary(json.output);
|
||||||
|
|
||||||
@@ -78,6 +84,9 @@ export const compileCode = async (activeId: number) => {
|
|||||||
file.lastCompiled = new Date();
|
file.lastCompiled = new Date();
|
||||||
file.compiledValueSnapshot = file.content
|
file.compiledValueSnapshot = file.content
|
||||||
file.compiledWatContent = wast;
|
file.compiledWatContent = wast;
|
||||||
|
} catch (error) {
|
||||||
|
throw Error("Invalid compilation result produced, check your code for errors and try again!")
|
||||||
|
}
|
||||||
|
|
||||||
toast.success("Compiled successfully!", { position: "bottom-center" });
|
toast.success("Compiled successfully!", { position: "bottom-center" });
|
||||||
state.logs.push({
|
state.logs.push({
|
||||||
@@ -97,12 +106,19 @@ export const compileCode = async (activeId: number) => {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
else if (err instanceof Error) {
|
||||||
|
state.logs.push({
|
||||||
|
type: "error",
|
||||||
|
message: err.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
state.logs.push({
|
state.logs.push({
|
||||||
type: "error",
|
type: "error",
|
||||||
message: "Something went wrong, check your connection try again later!",
|
message: "Something went wrong, come back later!",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
state.compiling = false;
|
state.compiling = false;
|
||||||
toast.error(`Error occurred while compiling!`, { position: "bottom-center" });
|
toast.error(`Error occurred while compiling!`, { position: "bottom-center" });
|
||||||
file.containsErrors = true
|
file.containsErrors = true
|
||||||
|
|||||||
Reference in New Issue
Block a user