Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async/await - Parsing error: Unexpected token => (null) #528

Closed
purepear opened this issue May 24, 2016 · 4 comments

Comments

@purepear
Copy link

commented May 24, 2016

export function loadThings (creds) {
  return async (dispatch, getState) => {
    try {
      const response = await fetch('http://localhost/api/things')
      return response
    } catch (err) {
      throw (err)
    }
  }
}
@LinusU

This comment has been minimized.

Copy link
Member

commented May 24, 2016

Totally unrelated but I couldn't help myself, you don't need to catch and then throw the same error. This function would be functionally equivalent:

export function loadThings (creds) {
  return async (dispatch, getState) => {
    return await fetch('http://localhost/api/things')
  }
}

Anyways, you need to use the babel-parser to use ESnext syntax, see here:

https://github.com/feross/standard#can-i-use-a-custom-js-parser-for-bleeding-edge-es6-or-es7-support

@purepear

This comment has been minimized.

Copy link
Author

commented May 24, 2016

@LinusU The code is actually out of context. Got it from a demo source and stripped it. But thanks for the advice. There's some additional error handling in the catch statement

@LinusU

This comment has been minimized.

Copy link
Member

commented May 24, 2016

Cool, I happened to press send a bit early, did you see the solution to your problem?

@purepear

This comment has been minimized.

Copy link
Author

commented May 24, 2016

I did now :)
Thanks!

@purepear purepear closed this May 24, 2016

@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
2 participants
You can’t perform that action at this time.