HTTP Error

19 views
Skip to first unread message

Frederic Jacquemin

unread,
Nov 26, 2013, 4:07:09 PM11/26/13
to locomo...@googlegroups.com
Hi Guys!

got this.res.status(500) giving me some resistance : 'TypeError: Cannot call method 'status' of undefined';..

this is basic ExpressJS stuff though.

need help to simply return a single 404 or 500...


Thanks for the help & keep up posting on this group, this makes development & bug fixing lot easier :)


Cheers,
Frederic

David Roncancio

unread,
Nov 26, 2013, 4:08:11 PM11/26/13
to locomo...@googlegroups.com
there is no res in this :P, can you put that line in some context

David Roncancio
(+57) 3014311354


--
You received this message because you are subscribed to the Google Groups "Locomotive" group.
To unsubscribe from this group and stop receiving emails from it, send an email to locomotivejs...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Frederic Jacquemin

unread,
Nov 27, 2013, 2:08:53 AM11/27/13
to locomo...@googlegroups.com
thanks David for the quick reply,
Got to bed (CET time :) so couldn't answer you
anyway : this line is used in a controller   : 

fs.readFile(this.req.files.image.path, function (err, data) {
 // ...
 var newPath = __dirpath__ + Date.now() + "_.jpg";
 fs.writeFile(newPath, data, function (err) {
   this.res.status(500).send('Server Error : Could not save your file.');
 });
});

I'm currently evaluating Locomotive, seems very promising, I really like it.

Thanks to let me know if you find something
Regards,
F.

Jared Hanson

unread,
Nov 27, 2013, 10:24:18 AM11/27/13
to locomo...@googlegroups.com
You need to put "var self = this" above the "fs.readFile" call, and then do "self.res.status..."

Inside the callback, the "this" context is different, and no longer refers to the controller.

Sent from my iPhone

Frederic Jacquemin

unread,
Nov 27, 2013, 10:27:04 AM11/27/13
to locomo...@googlegroups.com
well, I must have been completely blind not seeing this obvious point...
thanks Jared for the help & sorry for this post.

Regards,
Frederic


--
You received this message because you are subscribed to a topic in the Google Groups "Locomotive" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/locomotivejs/Vjg02pswmhQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to locomotivejs...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages