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

custom remote method doesn't check for accepts type #603

Closed
0xgeert opened this issue Oct 1, 2014 · 3 comments
Closed

custom remote method doesn't check for accepts type #603

0xgeert opened this issue Oct 1, 2014 · 3 comments

Comments

@0xgeert
Copy link

0xgeert commented Oct 1, 2014

Given a remote method defined as (partial):

accepts: [{ arg: 'payload', type: ['object'], http: { source: 'body' }, required: true}] ,

I expected the method to return a 400 bad request or something when the argument payload (i.e.: the body of the post in the case) isn't an array of objects. However, it seems to take any valid json.

Is this expected?

@bajtos bajtos added the api/ux label Oct 2, 2014
@frankcarey
Copy link

Yeah, I have a similar issue where when I set type to 'number', there isn't any error when passing a string like 'asdf' into the explorer. The 'asdf' then comes into the custom method as NaN, so I had to add some custom checking for that like so:

    myModel.getWeather = function(latitude, longitude, cb) {
      // rest connector doesn't check properly. Strings come in
      // as NaN when type accepts.type == 'number';
      if(isNaN(latitude) || isNaN(longitude)) {
        var err = new Error();
        err.status = 400;
        err.message = "Lat and long must be numbers";

        return cb(err);
      }

      //Do my usual stuff knowing that these should be numbers now.
      cb();
    }

@bajtos
Copy link
Member

bajtos commented Oct 15, 2014

I believe the arguments are converted in SharedMethod.prototype.invoke, it should be reasonable easy to add validations.

@gebrits @frankcarey Would you mind submitting a pull request implementing the changes you need?

@bajtos bajtos added this to the #Epic: Coercion Cleanup milestone Jun 2, 2016
@bajtos bajtos added the bug label Jun 2, 2016
@bajtos
Copy link
Member

bajtos commented Jun 2, 2016

Closing as a duplicate of #2092 where a more recent discussion is taking place.

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

No branches or pull requests

3 participants