Commit 2cf4353f authored by Raghav Khanna's avatar Raghav Khanna

Use async and await function return. If nor error update state.

parent c246e9ac
......@@ -69,11 +69,13 @@ class App extends React.Component {
test = "";
}
processWaccCode = (code) => {
let rsp = sendWaccCode(code)
console.log(rsp)
let graph = astMetaToGraphData(rsp.astMeta)
processWaccCode = async (code) => {
let rsp = await sendWaccCode(code);
let graph = this.state.graphData;
if (typeof rsp.isError !== "undefined") {
} else {
graph = astMetaToGraphData(rsp.astMeta);
this.setState({
arm: {code: rsp.armCode},
js: {code: rsp.jsCode},
......@@ -81,6 +83,9 @@ class App extends React.Component {
})
}
}
render() {
return (
<div className="App">
......
......@@ -17,16 +17,19 @@ export function astMetaToGraphData(astMeta) {
}
export async function sendWaccCode(code) {
let ADDR = SERVER_ADDR + SERVER_ENDPOINT
// console.log(`Sending ${code} to ${ADDR}`)
let ADDR = SERVER_ADDR + SERVER_ENDPOINT;
var data = {isError: true};
await axios.post(ADDR, {contents: code}, {headers:{'Content-Type': 'application/json'}})
.then(res => {
console.log(res.data)
return res.data
// console.log(res)
})
.catch(reason => {
// console.log(reason)
return
data = res.data
})
.catch(error => {
if(typeof error.response.data.errors !== "undefined" ){
var errors = error.response.data.errors;
for (let entry of errors.keys()) {
console.log(errors[entry])
}
}
});
return data
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment