bug with localization plugin
This commit is contained in:
@@ -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]) {
|
||||||
|
|||||||
@@ -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: [
|
||||||
|
|||||||
Reference in New Issue
Block a user