bug with localization plugin

This commit is contained in:
James
2020-02-10 16:38:07 -05:00
parent b0592981f1
commit ca62669c7b
2 changed files with 23 additions and 7 deletions

View File

@@ -138,7 +138,7 @@ module.exports = function localizationPlugin(schema, options) {
}) })
.set(function (value) { .set(function (value) {
// multiple locales are set as an object // multiple locales are set as an object
if (typeof value === 'object' && !Array.isArray(value)) { if (value && typeof value === 'object' && !Array.isArray(value)) {
const { locales } = this.schema.options.localization; const { locales } = this.schema.options.localization;
locales.forEach((locale) => { locales.forEach((locale) => {
if (!value[locale]) { if (!value[locale]) {

View File

@@ -1,14 +1,30 @@
const formatErrorResponse = (incoming, source) => { const formatErrorResponse = (incoming, source) => {
switch (source) { switch (source) {
case 'mongoose': case 'mongoose':
if (incoming && incoming.errors) {
return {
errors: Object.keys(incoming.errors).reduce((acc, key) => {
acc.push({
message: incoming.errors[key].message,
});
return acc;
}, []),
};
}
// If the Mongoose error does not get returned with incoming && incoming.errors,
// it's of a type that we really don't know how to handle. Sometimes this means a TypeError,
// which we might be able to manipulate to get the error message itself and send that back.
return { return {
errors: Object.keys(incoming.errors).reduce((acc, key) => { errors: [
acc.push({ {
message: incoming.errors[key].message, message: 'An unknown error occurred.',
}); },
return acc; ],
}, []),
}; };
case 'APIError': case 'APIError':
return { return {
errors: [ errors: [