balderdashy / balderdashy/sails

Parasails custom error handling

Open
#7,112 2 comments 0 reactions 0 assignees View on GitHub
does this answer your question? more info please
Dominant language
JavaScript
Stars
22.8k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

**Node version**: v14.15.1
**Sails version** : 1.4.0
**Parasails**: v0.9.2
**ORM hook version** : 2.1.1
**Sockets hook version** : 2.0.0
**Grunt hook version**: 4.0.0
**DB adapter & version**: 1.0.1
**Vuelidate**: v0.7.6


### Description
Hello!

I integrated vuelidate for client form validations with Sails, it works perfeclty with the validations that the plugin comes with out of the box, but when I try to add a custom validation the way the error works is by **resolving or rejecting a promise**, take a look a the [example](https://vuelidate.js.org/#sub-asynchronous-validation)

Here is a short example of what I'm currently doing:
```javascript
parasails.registerPage('create-legal-process', {
mixins: [window.vuelidate.validationMixin],
data: {
// we should define formData equal to the form in 'validations'
formData: {
code: ''
},

},

validations: {
formData: {
code: {
// the 'required' validation works, it comes out of the box
required: validators.required,

// this is a custom async validation, I'm using throttle to reduce the amount of requests
isUnique: _.throttle(async (value) => {
if (value === '') {
return true;
}

// query language for sails api
var params = {
where: JSON.stringify({
code: value
})
};
// perform request
var { data: process } = await axios.get('/legalprocess', { params });

// if the list isnt empty then throw error
if (legalprocess.length > 0) {
throw 'There\'s a legal process with that code already.';
} else {
// if it works just return anything that resolves correctly
return 'That code isn\'t being used yet.';
}
}, 1000),
},
},
},
});
```

### Expected behavior
I would like to throw errors in a way that I can continue to use this plugin, maybe throw an error with a specific code like `E_CLIENT_VALIDATION` that can be tolerated so that it doesn't display the error overlay, but if there's any **workaround** I'd like to know.

Thanks for your time, I love Sails!

Contributor guide

Open the contributing guide

Research direction

Start with the parasails.registerPage example in the issue and review Vuelidate's asynchronous validation behavior, especially how rejected promises are surfaced. Then trace how Parasails handles the resulting client-side error and compare it with the requested E_CLIENT_VALIDATION behavior; done means the supported handling or workaround is documented and the error no longer shows the unwanted overlay.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.