Skip to content
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

customized remote method cannot return with status code 200 #3370

Closed
seanxlliu opened this issue Apr 22, 2017 · 3 comments
Closed

customized remote method cannot return with status code 200 #3370

seanxlliu opened this issue Apr 22, 2017 · 3 comments

Comments

@seanxlliu
Copy link

seanxlliu commented Apr 22, 2017

Thanks for the great job.

My issue is as title.
To reproduce the issue, creates a standard remote method and specifies the default status code as 200, like following,

   module.exports = function(Person){

    Person.greet = function(msg, cb) {
      cb(null, 'Greetings... ' + msg);
    }

    Person.remoteMethod('greet', {
          accepts: {arg: 'msg', type: 'string'},
          //returns: {arg: 'greeting', type: 'string'}, // remove this
          http: { status: 200}
    });
   };

but 'status 200' is ignored and still returns 204.
I know it is forced when returning no content. Any workaround or did I make a mistake in the code? I searched the whole repository but didn't find the code to how the default was set to 204. Please help to point the file who did the 'magic'. Any clues are appreciated.

@bajtos
Copy link
Member

bajtos commented Apr 28, 2017

Here is the code setting the status code when the response body is missing:

https://github.com/strongloop/strong-remoting/blob/14a03ccfd9a9b4210d3e68e9a87ed76e07948b6e/lib/http-context.js#L575-L577

    if (res.statusCode === undefined || res.statusCode === 200) {
      res.statusCode = 204;
    }

@stale
Copy link

stale bot commented Sep 6, 2017

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

@regevbr
Copy link

regevbr commented Feb 3, 2019

I added returns: {arg: 'greeting', type: 'string'} and called the callback with empty string - sadly that is the only solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants