From eaeef78eb684af437e5e10fed652d83102671cff Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Wed, 1 Feb 2017 16:11:01 -0800 Subject: [PATCH] release 1.3.0 --- CHANGELOG.md | 7 +++++++ dist/index.js | 6 +++++- dist/index.js.map | 2 +- package.json | 2 +- src/index.js | 2 ++ 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea639ff..f909826 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ + +1.3.0 / 2017-02-01 +================== + * Update README.md + * Add Beerpay's badge + * Added isInstance method + 1.2.1 / 2016-12-07 ================== * Fixed a bug with overriding message serialization diff --git a/dist/index.js b/dist/index.js index 7a099b5..db87256 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.formatError = exports.createError = undefined; +exports.isInstance = exports.formatError = exports.createError = undefined; var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); @@ -128,4 +128,8 @@ var formatError = exports.formatError = function formatError(originalError) { }); return error.serialize(); }; + +var isInstance = exports.isInstance = function isInstance(e) { + return e instanceof ApolloError; +}; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/index.js.map b/dist/index.js.map index 20173b4..da250f8 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/index.js"],"names":["errorMap","Map","DELIMITER","serializeName","arr","reduce","str","val","length","toString","deserializeName","name","split","ApolloError","message","time_thrown","Date","toISOString","data","options","t","arguments","thrown_at","d","Object","assign","m","opts","JSON","stringify","_name","_humanized_message","_time_thrown","_data","_locations","showLocations","locations","_path","showPath","path","error","createError","e","bind","set","formatError","originalError","returnNull","undefined","parse","CustomError","get","serialize"],"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;;;AAEA,IAAMA,WAAW,IAAIC,GAAJ,EAAjB;;AAEA,IAAMC,YAAY,MAAlB;;AAEA,IAAMC,gBAAgB,SAAhBA,aAAgB;AAAA,MAACC,GAAD,uEAAO,EAAP;AAAA,SAAcA,IACjCC,MADiC,CAC1B,UAACC,GAAD,EAAMC,GAAN;AAAA,iBACHD,IAAIE,MAAJ,GAAa,CAAb,GAAiBF,MAAMJ,SAAvB,GAAmCI,GADhC,KACsCC,IAAIE,QAAJ,GAAeF,IAAIE,QAAJ,EAAf,GAAgCF,GADtE;AAAA,GAD0B,EAG/B,EAH+B,CAAd;AAAA,CAAtB;AAIA,IAAMG,kBAAkB,SAAlBA,eAAkB;AAAA,MAACC,IAAD,uEAAQ,EAAR;AAAA,SAAeA,KAAKC,KAAL,CAAWV,SAAX,CAAf;AAAA,CAAxB;;IAEMW,W;;;AACJ,uBAAaF,IAAb,QAKG;AAAA,QAJDG,OAIC,QAJDA,OAIC;AAAA,gCAHDC,WAGC;AAAA,QAHDA,WAGC,oCAHc,IAAIC,IAAJ,EAAD,CAAaC,WAAb,EAGb;AAAA,yBAFDC,IAEC;AAAA,QAFDA,IAEC,6BAFM,EAEN;AAAA,4BADDC,OACC;AAAA,QADDA,OACC,gCADS,EACT;;AAAA;;AACD,QAAMC,IAAKC,UAAU,CAAV,KAAgBA,UAAU,CAAV,EAAaC,SAA9B,IAA4CP,WAAtD;AACA,QAAMQ,IAAIC,OAAOC,MAAP,CAAc,EAAd,EAAkBP,IAAlB,EAA0BG,UAAU,CAAV,KAAgBA,UAAU,CAAV,EAAaH,IAA9B,IAAu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errorMap = new Map();\n\nconst DELIMITER = '/::/';\n\nconst serializeName = (arr = []) => arr\n .reduce((str, val) => (\n `${str.length > 0 ? str + DELIMITER : str}${val.toString ? val.toString() : val}`\n ), '');\nconst deserializeName = (name = '') => name.split(DELIMITER);\n\nclass ApolloError extends ExtendableError {\n constructor (name, {\n message,\n time_thrown = (new Date()).toISOString(),\n data = {},\n options = {},\n }) {\n const t = (arguments[2] && arguments[2].thrown_at) || time_thrown;\n const d = Object.assign({}, data, ((arguments[2] && arguments[2].data) || {}));\n const m = (arguments[2] && arguments[2].message) || message;\n const opts = Object.assign({}, options, ((arguments[2] && arguments[2].options) || {}));\n\n super(serializeName([\n name,\n t,\n (m !== message ? m : 'null'),\n Object.assign({}, d, {\n toString: () => JSON.stringify(d)\n }),\n ]));\n\n this._name = name;\n this._humanized_message = m || '';\n this._time_thrown = t;\n this._data = d;\n this._locations = (opts.showLocations && arguments[2] && arguments[2].locations)\n this._path = (opts.showPath && arguments[2] && arguments[2].path);\n }\n serialize () {\n const name = this._name;\n const message = this._humanized_message;\n const time_thrown = this._time_thrown;\n const data = this._data;\n const locations = this._locations;\n const path = this._path;\n let error = {\n message,\n name,\n time_thrown,\n data,\n };\n if (locations) error.locations = locations;\n if (path) error.path = path;\n return error;\n }\n}\n\nexport const createError = (name, data = { message: 'An error has occurred', options }) => {\n const e = ApolloError.bind(null, name, data);\n errorMap.set(name, e);\n return e;\n};\n\nexport const formatError = (originalError, returnNull = false) => {\n const [ name, thrown_at, m, d ] = deserializeName(originalError.message);\n const { locations, path } = originalError;\n const data = d !== undefined ? JSON.parse(d) : {};\n if (!name) return returnNull ? null : originalError;\n const CustomError = errorMap.get(name);\n if (!CustomError) return returnNull ? null : originalError;\n const error = new CustomError({\n message: m === 'null' ? undefined : m,\n thrown_at,\n data,\n locations,\n path,\n });\n return error.serialize();\n};\n"]} \ No newline at end of file +{"version":3,"sources":["../src/index.js"],"names":["errorMap","Map","DELIMITER","serializeName","arr","reduce","str","val","length","toString","deserializeName","name","split","ApolloError","message","time_thrown","Date","toISOString","data","options","t","arguments","thrown_at","d","Object","assign","m","opts","JSON","stringify","_name","_humanized_message","_time_thrown","_data","_locations","showLocations","locations","_path","showPath","path","error","createError","e","bind","set","formatError","originalError","returnNull","undefined","parse","CustomError","get","serialize","isInstance"],"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;;;AAEA,IAAMA,WAAW,IAAIC,GAAJ,EAAjB;;AAEA,IAAMC,YAAY,MAAlB;;AAEA,IAAMC,gBAAgB,SAAhBA,aAAgB;AAAA,MAACC,GAAD,uEAAO,EAAP;AAAA,SAAcA,IACjCC,MADiC,CAC1B,UAACC,GAAD,EAAMC,GAAN;AAAA,iBACHD,IAAIE,MAAJ,GAAa,CAAb,GAAiBF,MAAMJ,SAAvB,GAAmCI,GADhC,KACsCC,IAAIE,QAAJ,GAAeF,IAAIE,QAAJ,EAAf,GAAgCF,GADtE;AAAA,GAD0B,EAG/B,EAH+B,CAAd;AAAA,CAAtB;AAIA,IAAMG,kBAAkB,SAAlBA,eAAkB;AAAA,MAACC,IAAD,uEAAQ,EAAR;AAAA,SAAeA,KAAKC,KAAL,CAAWV,SAAX,CAAf;AAAA,CAAxB;;IAEMW,W;;;AACJ,uBAAaF,IAAb,QAKG;AAAA,QAJDG,OAIC,QAJDA,OAIC;AAAA,gCAHDC,WAGC;AAAA,QAHDA,WAGC,oCAHc,IAAIC,IAAJ,EAAD,CAAaC,WAAb,EAGb;AAAA,yBAFDC,IAEC;AAAA,QAFDA,IAEC,6BAFM,EAEN;AAAA,4BADDC,OACC;AAAA,QADDA,OACC,gCADS,EACT;;AAAA;;AACD,QAAMC,IAAKC,UAAU,CAAV,KAAgBA,UAAU,CAAV,EAAaC,SAA9B,IAA4CP,WAAtD;AACA,QAAMQ,IAAIC,OAAOC,MAAP,CAAc,EAAd,EAAkBP,IAAlB,EAA0BG,UAAU,CAAV,KAAgBA,UAAU,CAAV,EAAaH,IAA9B,IAAuC,EAAhE,CAAV;AACA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B;AAAA,CAAnB","file":"index.js","sourcesContent":["import ExtendableError from 'es6-error';\n\nconst errorMap = new Map();\n\nconst DELIMITER = '/::/';\n\nconst serializeName = (arr = []) => arr\n .reduce((str, val) => (\n `${str.length > 0 ? str + DELIMITER : str}${val.toString ? val.toString() : val}`\n ), '');\nconst deserializeName = (name = '') => name.split(DELIMITER);\n\nclass ApolloError extends ExtendableError {\n constructor (name, {\n message,\n time_thrown = (new Date()).toISOString(),\n data = {},\n options = {},\n }) {\n const t = (arguments[2] && arguments[2].thrown_at) || time_thrown;\n const d = Object.assign({}, data, ((arguments[2] && arguments[2].data) || {}));\n const m = (arguments[2] && arguments[2].message) || message;\n const opts = Object.assign({}, options, ((arguments[2] && arguments[2].options) || {}));\n\n super(serializeName([\n name,\n t,\n (m !== message ? m : 'null'),\n Object.assign({}, d, {\n toString: () => JSON.stringify(d)\n }),\n ]));\n\n this._name = name;\n this._humanized_message = m || '';\n this._time_thrown = t;\n this._data = d;\n this._locations = (opts.showLocations && arguments[2] && arguments[2].locations)\n this._path = (opts.showPath && arguments[2] && arguments[2].path);\n }\n serialize () {\n const name = this._name;\n const message = this._humanized_message;\n const time_thrown = this._time_thrown;\n const data = this._data;\n const locations = this._locations;\n const path = this._path;\n let error = {\n message,\n name,\n time_thrown,\n data,\n };\n if (locations) error.locations = locations;\n if (path) error.path = path;\n return error;\n }\n}\n\nexport const createError = (name, data = { message: 'An error has occurred', options }) => {\n const e = ApolloError.bind(null, name, data);\n errorMap.set(name, e);\n return e;\n};\n\nexport const formatError = (originalError, returnNull = false) => {\n const [ name, thrown_at, m, d ] = deserializeName(originalError.message);\n const { locations, path } = originalError;\n const data = d !== undefined ? JSON.parse(d) : {};\n if (!name) return returnNull ? null : originalError;\n const CustomError = errorMap.get(name);\n if (!CustomError) return returnNull ? null : originalError;\n const error = new CustomError({\n message: m === 'null' ? undefined : m,\n thrown_at,\n data,\n locations,\n path,\n });\n return error.serialize();\n};\n\nexport const isInstance = e => e instanceof ApolloError;\n"]} \ No newline at end of file diff --git a/package.json b/package.json index b426957..3571ab5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "apollo-errors", - "version": "1.2.1", + "version": "1.3.0", "description": "Machine-readable custom errors for Apollostack's GraphQL server", "main": "dist/index.js", "scripts": { diff --git a/src/index.js b/src/index.js index 0ff50fb..0733aaa 100644 --- a/src/index.js +++ b/src/index.js @@ -79,3 +79,5 @@ export const formatError = (originalError, returnNull = false) => { }); return error.serialize(); }; + +export const isInstance = e => e instanceof ApolloError;