Skip to content
This repository was archived by the owner on Jun 28, 2022. It is now read-only.
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

Description

@Martian2Lee
      .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.

Activity

  1. nathanhannig commented on Sep 8, 2017

    @nathanhannig

    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

  2. Martian2Lee commented on Sep 8, 2017

    @Martian2Lee
    Author

    @breakpoint25 Absolutely!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions