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

TypeError on empty response from HTTP request #71

Closed
hieronx opened this issue Jun 14, 2015 · 8 comments
Closed

TypeError on empty response from HTTP request #71

hieronx opened this issue Jun 14, 2015 · 8 comments
Assignees
Labels
Milestone

Comments

@hieronx
Copy link
Contributor

hieronx commented Jun 14, 2015

I've got the following Service for retrieving some data from our API:

class UserService($http: HttpService) extends Service {
   def findMe(): HttpPromise[User] = $http.get(s"$host/users/me")
}

And I'm calling this using the following code:

54:   userService.findMe() onComplete {
55:      case Success(data) => js.Dynamic.global.console.log(data)
56:      case Failure(ex) => js.Dynamic.global.console.error(s"An error has occurred: $ex")
57:   }

Now, when /users/me returns a 200 OK with the correct data, it works perfectly. However, when it returns either a 404 or 405 without any response data, the following error occurs instead of triggering the Failure case:

TypeError: Cannot read property 'toString' of null
    at $objectToString (scalajsenv.js:192)
    at App.scala:54
    [..]

App.scala:54 returns to the onComplete method in the 2nd code block. This seems somewhat similar to #22, yet I'm using the latest version (0.2.2-SNAPSHOT), so it should already be fixed. Any thoughts on what's going on here?

@jokade
Copy link
Owner

jokade commented Jun 15, 2015

Does this error also occur, when you use onSuccess and onFailure instead of onComplete?

@hieronx
Copy link
Contributor Author

hieronx commented Jun 15, 2015

Same problem, I've tried the following:

userService.findMe() onSuccess {
   case data => js.Dynamic.global.console.log(data)
}

userService.findMe() onFailure {
   case ex => js.Dynamic.global.console.error(s"An error has occurred: $ex")
}

This creates the same error message:

TypeError: Cannot read property 'toString' of null
    at $objectToString (scalajsenv.js:192)
    at App.scala:61

App.scala:61 returns to the first line of the code block.

@jokade
Copy link
Owner

jokade commented Jun 15, 2015

Could you please check what happens if you use the bare bone Angular method error() instead of onFailure?

@hieronx
Copy link
Contributor Author

hieronx commented Jun 15, 2015

Yeah, the following code works just like it should:

userService.findMe().success((data: String, status: Int) =>
   js.Dynamic.global.console.log(data)
)

userService.findMe().error((data: String, status: Int) =>
   js.Dynamic.global.console.error(data)
)

@jokade
Copy link
Owner

jokade commented Jun 15, 2015

Thanks; I have to check the macro code, but that will take some time (I'm currently preoccupied with other stuff)...

@hieronx
Copy link
Contributor Author

hieronx commented Jun 15, 2015

Of course, I can just use the plain angular promise methods for now. Let me know if you need any more debugging from my end later on.

@jokade jokade added the bug label Jun 15, 2015
@jokade jokade added this to the v0.2.2 milestone Jun 15, 2015
@jokade jokade self-assigned this Jun 15, 2015
@jokade
Copy link
Owner

jokade commented Jun 15, 2015

@offerijns I think I've solved the issue in the current 0.2.2-SNAPSHOT; could you please verify?

@hieronx
Copy link
Contributor Author

hieronx commented Jun 15, 2015

@jokade yes it's fixed, thanks a lot!

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

No branches or pull requests

2 participants