Skip to content

Aff doesn't fail when running on Node #44

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

Closed
beckyconning opened this issue Aug 31, 2015 · 9 comments
Closed

Aff doesn't fail when running on Node #44

beckyconning opened this issue Aug 31, 2015 · 9 comments
Labels
type: bug Something that should function correctly isn't.

Comments

@beckyconning
Copy link

The following program outputs [Log] onerror@file:///Users/beckyconning/Documents/purescript-sketchpad/index.js:9693:24 (index.js, line 1302) in a browser but is silent in Node.

It appears print is never called.

module Main where

import Prelude
import Debug.Trace

import Control.Monad.Aff
import Control.Monad.Eff.Console
import Data.Foreign
import Network.HTTP.Affjax

main = runAff print (print <<< show <<< _.status) $ (get "ajsdlfa" :: Affjax _ Foreign)
@jdegoes jdegoes added the type: bug Something that should function correctly isn't. label Aug 31, 2015
@stkb
Copy link
Contributor

stkb commented Oct 5, 2015

Have run into this issue too, and it's caused by the underlying xmlhttprequest module, which to be blunt, doesn't work very well. It doesn't support things like the onerror event (the cause of this issue) and would just cause my program to hang in the case of a redirect. There are forks of xmlhttprequest that have fixed various things but with issues and PR's piling up, development on the module seems to have stopped.

I went looking for a possible replacement and xhr2 seems to be a good one. I tried using it in my app instead of xmlhttprequest (with a one-line change in Affjax.js) and everything is working fine so far.

@paf31
Copy link

paf31 commented Oct 5, 2015

Perhaps purescript-node-http would be a good base for a Node HTTP client backend?

@stkb
Copy link
Contributor

stkb commented Oct 6, 2015

@paf31 Thanks for that; I'd also been looking for a PS library for a lightweight http server. Though for an http client, I like the Aff-style API that Affjax supplies, as well as being able to use the same API in both Node and the web browser.

@jdegoes
Copy link
Contributor

jdegoes commented Oct 6, 2015

PRs welcome! 😀 External dependencies should add minimal overhead to the library and be reflected in bower dependencies.

@stkb
Copy link
Contributor

stkb commented Oct 6, 2015

@jdegoes Thanks will submit a PR soon :) Am just checking everything works my end

@paf31
Copy link

paf31 commented Oct 6, 2015

Perhaps it would make sense to break a Node backend out into its own library, if dependencies are a concern. Creating an abstract backend should be straightforward enough, right? Something like type Backend eff = forall req res. (Requestable req, Respondable res) => req -> Affjax eff res.

@jdegoes
Copy link
Contributor

jdegoes commented Oct 6, 2015

I'm definitely open to feedback. I think a lot of people may run both node and browser tests in the same code base and want an Ajax library that does both; right now we sort of have node support in there but not for error cases.

@beckyconning
Copy link
Author

Personally one of the biggest attractions I have to Javascript and PureScript is that DSLs / libraries / patterns can be shared between backend services and clients. I'd prefer to address this inside of Affjax rather than having different modules for dealing with HTTP requests depending on the environment.

@beckyconning
Copy link
Author

But its the 'DSL' of Affjax that I think that would be valuable to share between the two rather than necessarily the implementation of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something that should function correctly isn't.
Development

No branches or pull requests

4 participants