bug with localization plugin
This commit is contained in:
@@ -138,7 +138,7 @@ module.exports = function localizationPlugin(schema, options) {
|
||||
})
|
||||
.set(function (value) {
|
||||
// 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;
|
||||
locales.forEach((locale) => {
|
||||
if (!value[locale]) {
|
||||
|
||||
@@ -1,14 +1,30 @@
|
||||
const formatErrorResponse = (incoming, source) => {
|
||||
switch (source) {
|
||||
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 {
|
||||
errors: Object.keys(incoming.errors).reduce((acc, key) => {
|
||||
acc.push({
|
||||
message: incoming.errors[key].message,
|
||||
});
|
||||
return acc;
|
||||
}, []),
|
||||
errors: [
|
||||
{
|
||||
message: 'An unknown error occurred.',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
case 'APIError':
|
||||
return {
|
||||
errors: [
|
||||
|
||||
Reference in New Issue
Block a user