Comparing version 0.2.4 to 0.2.5
@@ -16,15 +16,27 @@ 'use strict'; | ||
let message = error.message; | ||
const keyword = error.keyword; | ||
const params = error.params; | ||
if (!error.keyword) { | ||
if (!keyword) { | ||
return { message }; | ||
} | ||
if (error.keyword === 'required') { | ||
if (keyword === 'required') { | ||
message = `${field} is required`; | ||
} else if (error.keyword === 'type') { | ||
const type = error.params.type; | ||
} else if (keyword === 'type') { | ||
const type = params.type; | ||
message = `${field} should be of type ${type}`; | ||
} else if (error.keyword === 'format') { | ||
const format = error.params.format; | ||
} else if (keyword === 'format') { | ||
const format = params.format; | ||
message = `${field} should be a valid ${format}`; | ||
} else if (keyword === 'minLength') { | ||
const limit = params.limit; | ||
if (limit === 1) { | ||
message = `${field} is required`; | ||
} else { | ||
message = `${field} must be larger than ${limit} chars`; | ||
} | ||
} else if (keyword === 'maxLength') { | ||
const limit = params.limit; | ||
message = `${field} must be shorter than ${limit} chars`; | ||
} | ||
@@ -38,5 +50,3 @@ | ||
if (process.env.NODE_ENV !== 'production') { | ||
error._stack = error.stack; | ||
} | ||
const isDev = process.env.NODE_ENV !== 'production'; | ||
@@ -47,2 +57,7 @@ const originalError = error.originalError || error; | ||
if (isDev) { | ||
error._stack = error.stack; | ||
error._type = errorType; | ||
} | ||
if (errorType === 'ValidationError' || errorType === 'UserError') { | ||
@@ -65,2 +80,7 @@ if (_lodash2.default.isString(message)) { | ||
if (isDev) { | ||
error._originalData = originalError.data; | ||
error._originalMessage = originalError.message; | ||
} | ||
error.message = 'Your query has errors'; | ||
@@ -101,2 +121,6 @@ } else if (errorType === 'GraphQLError' && _lodash2.default.isString(message)) { | ||
} else { | ||
if (isDev) { | ||
error._originalMessage = error.message; | ||
} | ||
error.message = 'Server error'; | ||
@@ -103,0 +127,0 @@ error.fields.global = { |
{ | ||
"name": "gqutils", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "Utilities For GraphQL", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -5,18 +5,33 @@ import _ from 'lodash'; | ||
let message = error.message; | ||
const keyword = error.keyword; | ||
const params = error.params; | ||
if (!error.keyword) { | ||
if (!keyword) { | ||
return {message}; | ||
} | ||
if (error.keyword === 'required') { | ||
if (keyword === 'required') { | ||
message = `${field} is required`; | ||
} | ||
else if (error.keyword === 'type') { | ||
const type = error.params.type; | ||
else if (keyword === 'type') { | ||
const type = params.type; | ||
message = `${field} should be of type ${type}`; | ||
} | ||
else if (error.keyword === 'format') { | ||
const format = error.params.format; | ||
else if (keyword === 'format') { | ||
const format = params.format; | ||
message = `${field} should be a valid ${format}`; | ||
} | ||
else if (keyword === 'minLength') { | ||
const limit = params.limit; | ||
if (limit === 1) { | ||
message = `${field} is required`; | ||
} | ||
else { | ||
message = `${field} must be larger than ${limit} chars`; | ||
} | ||
} | ||
else if (keyword === 'maxLength') { | ||
const limit = params.limit; | ||
message = `${field} must be shorter than ${limit} chars`; | ||
} | ||
@@ -29,5 +44,3 @@ return {message}; | ||
if (process.env.NODE_ENV !== 'production') { | ||
error._stack = error.stack; | ||
} | ||
const isDev = process.env.NODE_ENV !== 'production'; | ||
@@ -38,2 +51,7 @@ const originalError = error.originalError || error; | ||
if (isDev) { | ||
error._stack = error.stack; | ||
error._type = errorType; | ||
} | ||
if (errorType === 'ValidationError' || errorType === 'UserError') { | ||
@@ -59,2 +77,7 @@ if (_.isString(message)) { | ||
if (isDev) { | ||
error._originalData = originalError.data; | ||
error._originalMessage = originalError.message; | ||
} | ||
error.message = 'Your query has errors'; | ||
@@ -97,2 +120,6 @@ } | ||
else { | ||
if (isDev) { | ||
error._originalMessage = error.message; | ||
} | ||
error.message = 'Server error'; | ||
@@ -99,0 +126,0 @@ error.fields.global = { |
109174
812