Skip to content
This repository was archived by the owner on Jun 28, 2022. It is now read-only.

Bug in server.js - SyntaxError: Unexpected end of JSON input #8

Open
Martian2Lee opened this issue Aug 31, 2017 · 2 comments
Open

Bug in server.js - SyntaxError: Unexpected end of JSON input #8

Martian2Lee opened this issue Aug 31, 2017 · 2 comments

Comments

@Martian2Lee
Copy link

      .then(
          (post) => {
              comments.disableByParent(req.token, post)
          })
      .then(
          (data) => res.send(data),
          (error) => {
              console.error(error)
              res.status(500).send({
                  error: 'There was an error.'
              })
          }
      )

should be

        .then(
            (post) => {
                comments.disableByParent(req.token, post)
                res.send(post)
            },
            (error) => {
                console.error(error)
                res.status(500).send({
                    error: 'There was an error.'
                })
            })

other wise console.log(data) before (data) => res.send(data) will get undefined, and if you try .then(res => res.json()) after fetch() in your api.js, you will get SyntaxError: Unexpected end of JSON input.

@nathanhannig
Copy link

nathanhannig commented Sep 8, 2017

I believe the correct fix is to just remove the curly brackets in the first .then() since disableByParent is a function that returns a Promise.

app.delete('/posts/:id', (req, res) => {
    posts.disable(req.token, req.params.id)
      .then(
          (post) =>
              comments.disableByParent(req.token, post)
          )
      .then(
          (data) => res.send(data),
          (error) => {
              console.error(error)
              res.status(500).send({
                  error: 'There was an error.'
              })
          }
      )
})

A pull request was opened here with same
#6

@Martian2Lee
Copy link
Author

@breakpoint25 Absolutely!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants