meteor / meteor/validation-error
ValidationError.is(error) failing when using mdg:validated-method (err.error = 400)
- Dominant language
- JavaScript
- Stars
- 12
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
In my front-end code I have the following check:
``` js
const onNameChange = (name) => {
StaticText.methods.updateName.call({
staticTextId: fixedText._id,
newName: name,
}, (error) => {
if (ValidationError.is(error)) { // This line doesn't pass the logic-test
error.details.forEach((fieldError) => {
console.log(fieldError.type);
});
}
});
};
```
And the following method, using `mdg:validated-method`:
``` js
StaticText.methods.updateName = new ValidatedMethod({
name: 'StaticText.methods.updateName',
validate: new SimpleSchema({
staticTextId: { type: String },
newName: { type: String, trim: false },
}).validator(),
run({ staticTextId, newName }) {
const staticText = StaticText.findOne(staticTextId);
if (!staticText) {
return throwError('not-found', 'The specified static text does not exist');
}
checkUserIsOwner(staticText);
return StaticText.update(staticTextId, {
$set: { name: newName },
}, {
autoConvert: false,
});
}
});
```
The line that fails the check is this, in the `validation-error` package, `err.error` seems to be set to `400` rather than the expected `ValidationError.ERROR_CODE` for some reason.
``` js
// Static method checking if a given Meteor.Error is an instance of
// ValidationError.
static is(err) {
return err instanceof Meteor.Error && err.error === ValidationError.ERROR_CODE;
};
```
Am I missing something!? I am using Simple Schema v1.5.3
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the validation-error package's ValidationError.is method, then reproduce the shown StaticText.methods.updateName call using mdg:validated-method and SimpleSchema v1.5.3. Compare the returned Meteor.Error fields with ValidationError.ERROR_CODE; done means the reported validation error is consistently recognized or the incompatibility is clearly documented and covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100