How can i modify the statusCode in remote methods?

831 views
Skip to first unread message

Roli B.

unread,
Sep 9, 2014, 4:09:58 PM9/9/14
to loopb...@googlegroups.com
Hi 

How can i modify the statusCode in remote methods?  i want to send 400 status code

User.something = function (cb) {
  
 cb('you need enter  foo attribute');
}

Thanks.

Raymond Feng

unread,
Sep 9, 2014, 4:11:18 PM9/9/14
to Roli B., loopb...@googlegroups.com
var err = new Error('you need enter  foo attribute’);
err.statusCode = 400;
cb(err);

Thanks,

---
Raymond Feng
Co-Founder and Architect @ StrongLoop, Inc.

StrongLoop makes it easy to develop APIs in Node, plus get DevOps capabilities like monitoring, debugging and clustering.

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

Roli B.

unread,
Sep 9, 2014, 4:35:37 PM9/9/14
to loopb...@googlegroups.com
Thanks 

It is working well.

How can i disable stackTrace error ?

Raymond Feng

unread,
Sep 9, 2014, 4:45:56 PM9/9/14
to Roli B., loopb...@googlegroups.com
set NODE_ENV=production or {disableStrackTrace: true} for the loopback.rest middleware (look under server/boot/rest-api.js).

Thanks,

---
Raymond Feng
Co-Founder and Architect @ StrongLoop, Inc.

StrongLoop makes it easy to develop APIs in Node, plus get DevOps capabilities like monitoring, debugging and clustering.

Raymond Feng

unread,
Sep 9, 2014, 4:56:01 PM9/9/14
to Roli B., loopb...@googlegroups.com
You should be able to configure it in server/config.json too as follows:

{
  “remoting”: 
    “errorHandler”: {
      “disableStackTrace”: true
    }
}

Thanks,

---
Raymond Feng
Co-Founder and Architect @ StrongLoop, Inc.

StrongLoop makes it easy to develop APIs in Node, plus get DevOps capabilities like monitoring, debugging and clustering.

Roli B.

unread,
Sep 9, 2014, 5:35:18 PM9/9/14
to loopb...@googlegroups.com
Thank you so much.
Reply all
Reply to author
Forward
0 new messages