isomorphic-lab icon indicating copy to clipboard operation
isomorphic-lab copied to clipboard

404 when resource on server not found

Open joa-queen opened this issue 8 years ago • 2 comments

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.

joa-queen avatar Aug 14 '15 03:08 joa-queen

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.

fraserxu avatar Aug 14 '15 03:08 fraserxu

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

Sorry if I am too lost.

joa-queen avatar Aug 14 '15 04:08 joa-queen