223 reject({ fn: 'NotFound', message: 'Vulnerability not found' });
224 else {
225 if (row.details.findIndex(d => d.locale === locale && d.title) !== -1)
226 reject({227 fn: 'BadParameters',228 message: 'Language already exists in this vulnerability',229 });230 else {
231 primeVuln = row;
232 var removeIndex = mergeVuln.details
220 })
221 .then(row => {
222 if (!row)
223 reject({ fn: 'NotFound', message: 'Vulnerability not found' });224 else {
225 if (row.details.findIndex(d => d.locale === locale && d.title) !== -1)
226 reject({
210 .exec()
211 .then(row => {
212 if (!row)
213 reject({ fn: 'NotFound', message: 'Vulnerability not found' });214 else {
215 mergeVuln = row;
216 mergeDetail = row.details.find(d => d.locale === locale);
189 });
190 resolve(result);
191 } else
192 reject({193 fn: 'NotFound',194 message: 'Locale with existing title not found',195 });196 })
197 .catch(err => {
198 reject(err);
155 .exec()
156 .then(rows => {
157 if (rows) resolve(rows);
158 else reject({ fn: 'NotFound', message: 'Vulnerability not found' });159 })
160 .catch(err => {
161 reject(err);
It is considered good practice to only pass instances of the built-in Error
object to the reject()
function for user-defined errors in Promises
. Error
objects automatically store a stack trace, which can be used to debug an error by determining where it came from. If a Promise
is rejected with a non-Error
value, it can be difficult to determine where the rejection occurred.
It helps us to ensure that Promises are rejected with Error
objects.
Promise.reject("something bad happened");
Promise.reject(5);
Promise.reject();
new Promise(function(resolve, reject) {
reject("something bad happened");
});
new Promise(function(resolve, reject) {
reject();
});
Promise.reject(new Error("something bad happened"));
Promise.reject(new TypeError("something bad happened"));
new Promise(function(resolve, reject) {
reject(new Error("something bad happened"));
});
var foo = getUnknownValue();
Promise.reject(foo);