Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
]
});
if (embed) {
return embed.metadata;
}
// 2. if not or not older then x minutes, get fresh data and save it to the database
let metadata = await getMetadata(url, Provider);
try {
metadata = Provider.enrichMetadata(metadata);
} catch (err) {
// console.error(err);
}
if (!metadata.title && !metadata.site_name) {
throw new errors.NotFound('no data found for url');
}
try {
await this.embeds.create({
url,
metadata
});
} catch (err) {
// console.error(err);
}
// 3. return cached or fresh metadata
return metadata;
}
case 1:
case 8:
case 18:
case 19:
case 20:
feathersError = new errors.BadRequest(error);
break;
case 2:
feathersError = new errors.Unavailable(error);
break;
case 3:
case 23:
feathersError = new errors.Forbidden(error);
break;
case 12:
feathersError = new errors.NotFound(error);
break;
default:
feathersError = new errors.GeneralError(error);
break;
}
throw feathersError;
}
// Objection validation error
if (error.statusCode) {
switch (error.statusCode) {
case 400:
feathersError = new errors.BadRequest(error);
break;
async function getActiveRecord (options, context) {
const record = await (options.probeCall || defaultProbeCall)(context, options);
if (record[options.deletedAt || defaultDeletedAt] > -1) {
throw new errors.NotFound(deletedMessage, { id: context.id });
}
return record;
}
async get(id, params) {
const doc = this.docs[id]
if (!doc) throw new errors.NotFound(`No record found for id '${id}'`)
if (!doc.md) doc.md = await this.getMd(id)
return this.docs[id]
}
break;
case 401:
feathersError = new errors.NotAuthenticated(error);
break;
case 402:
feathersError = new errors.PaymentError(error);
break;
case 403:
feathersError = new errors.Forbidden(error);
break;
case 404:
feathersError = new errors.NotFound(error);
break;
case 405:
feathersError = new errors.MethodNotAllowed(error);
break;
case 406:
feathersError = new errors.NotAcceptable(error);
break;
case 408:
feathersError = new errors.Timeout(error);
break;
case 409:
feathersError = new errors.Conflict(error);
async _get (id, params = {}) {
if (id in this.store) {
const { query } = this.filterQuery(params);
const value = this.store[id];
if (this.options.matcher(query)(value)) {
return _select(value, params, this.id);
}
}
throw new errors.NotFound(`No record found for id '${id}'`);
}
return function (req, res, next) {
const { url } = req;
const message = `Page not found${verbose ? ': ' + url : ''}`;
next(new errors.NotFound(message, { url }));
};
};
case 'SequelizeValidationError':
case 'SequelizeUniqueConstraintError':
case 'SequelizeExclusionConstraintError':
case 'SequelizeForeignKeyConstraintError':
case 'SequelizeInvalidConnectionError':
throw wrap(new errors.BadRequest(message, { errors: error.errors }), error);
case 'SequelizeTimeoutError':
case 'SequelizeConnectionTimedOutError':
throw wrap(new errors.Timeout(message), error);
case 'SequelizeConnectionRefusedError':
case 'SequelizeAccessDeniedError':
throw wrap(new errors.Forbidden(message), error);
case 'SequelizeHostNotReachableError':
throw wrap(new errors.Unavailable(message), error);
case 'SequelizeHostNotFoundError':
throw wrap(new errors.NotFound(message), error);
default:
throw wrap(new errors.GeneralError(message), error);
}
}
throw error;
};