insin / isomorphic-lab

Isomorphic React experimentation
https://isomorphic-lab.herokuapp.com
144 stars 8 forks source link

404 when resource on server not found #7

Open joa-queen opened 9 years ago

joa-queen commented 9 years ago

Hi, I got this fetchData method in my component:

fetchData(params, cb) {
            superagent
                .get(`${API_URL}/users/` + params.username)
                .accept('json')
                .set('Api', 'v1')
                .end(function(err, res) {
                        cb(err, res && res.body);
                })
        },

How can I display a 404 message when the superagent returns a 404 from request?

Thanks.

fraserxu commented 9 years ago

404 is not catch here and it's not an error, you can check the res object and see the http status code, and then you can do whatever you want with it.

joa-queen commented 9 years ago

But since I'm into fetchData I need to return the cb, don't I?

Sorry if I am too lost.