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

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

parent c246e9ac
...@@ -69,11 +69,13 @@ class App extends React.Component { ...@@ -69,11 +69,13 @@ class App extends React.Component {
test = ""; test = "";
} }
processWaccCode = (code) => { processWaccCode = async (code) => {
let rsp = sendWaccCode(code) let rsp = await sendWaccCode(code);
console.log(rsp) let graph = this.state.graphData;
let graph = astMetaToGraphData(rsp.astMeta) if (typeof rsp.isError !== "undefined") {
} else {
graph = astMetaToGraphData(rsp.astMeta);
this.setState({ this.setState({
arm: {code: rsp.armCode}, arm: {code: rsp.armCode},
js: {code: rsp.jsCode}, js: {code: rsp.jsCode},
...@@ -81,6 +83,9 @@ class App extends React.Component { ...@@ -81,6 +83,9 @@ class App extends React.Component {
}) })
} }
}
render() { render() {
return ( return (
<div className="App"> <div className="App">
......
...@@ -17,16 +17,19 @@ export function astMetaToGraphData(astMeta) { ...@@ -17,16 +17,19 @@ export function astMetaToGraphData(astMeta) {
} }
export async function sendWaccCode(code) { export async function sendWaccCode(code) {
let ADDR = SERVER_ADDR + SERVER_ENDPOINT let ADDR = SERVER_ADDR + SERVER_ENDPOINT;
// console.log(`Sending ${code} to ${ADDR}`) var data = {isError: true};
await axios.post(ADDR, {contents: code}, {headers:{'Content-Type': 'application/json'}}) await axios.post(ADDR, {contents: code}, {headers:{'Content-Type': 'application/json'}})
.then(res => { .then(res => {
console.log(res.data) data = res.data
return res.data
// console.log(res)
})
.catch(reason => {
// console.log(reason)
return
}) })
.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