diff --git a/dist/index.js.map b/dist/index.js.map index 0458466..5c6d1ac 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/index.js"],"names":[],"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;;;AAEA,IAAM,WAAW,IAAI,GAAJ,EAAX;;AAEN,IAAM,YAAY,GAAZ;;AAEN,IAAM,gBAAgB,SAAhB,aAAgB;MAAC,0EAAM;SAAO,IAAI,MAAJ,CAAW,UAAC,GAAD,EAAM,GAAN;iBAAiB,IAAI,MAAJ,GAAa,CAAb,GAAiB,MAAM,SAAN,GAAkB,GAAnC,IAAyC;GAA1D,EAAiE,EAA5E;CAAd;AACtB,IAAM,kBAAkB,SAAlB,eAAkB,GAAe;MAAd,2EAAO,GAAO;;AACrC,MAAM,MAAM,EAAN,CAD+B;AAErC,MAAM,MAAM,KAAK,KAAL,CAAW,SAAX,CAAN,CAF+B;AAGrC,MAAI,IAAJ,CAAS,IAAI,KAAJ,EAAT,EAHqC;AAIrC,MAAI,IAAJ,CAAS,IAAI,IAAJ,CAAS,SAAT,CAAT,EAJqC;AAKrC,SAAO,GAAP,CALqC;CAAf;;IAQlB;;;AACJ,uBAAa,IAAb,QAIG;QAHD;gCACA;uDAAc,IAAK,IAAJ,EAAD,CAAa,WAAb;yBACd;yCAAO,eACN;;;;AACD,QAAM,IAAI,SAAC,CAAU,CAAV,KAAgB,UAAU,CAAV,EAAa,SAAb,IAA2B,WAA5C,CADT;AAED,QAAM,IAAI,OAAO,MAAP,CAAc,EAAd,EAAkB,IAAlB,EAAyB,SAAC,CAAU,CAAV,KAAgB,UAAU,CAAV,EAAa,IAAb,IAAsB,EAAvC,CAA7B,CAFL;;0HAIK,cAAc,CAClB,IADkB,EAElB,CAFkB,CAAd,IAJL;;AASD,UAAK,KAAL,GAAa,IAAb,CATC;AAUD,UAAK,kBAAL,GAA0B,WAAW,EAAX,CAVzB;AAWD,UAAK,YAAL,GAAoB,CAApB,CAXC;AAYD,UAAK,KAAL,GAAa,CAAb,CAZC;;GAJH;;;;gCAkBa;AACX,UAAM,OAAO,KAAK,KAAL,CADF;AAEX,UAAM,UAAU,KAAK,kBAAL,CAFL;AAGX,UAAM,cAAc,KAAK,YAAL,CAHT;AAIX,UAAM,OAAO,KAAK,KAAL,CAJF;AAKX,aAAO;AACL,wBADK;AAEL,kBAFK;AAGL,gCAHK;AAIL,kBAJK;OAAP,CALW;;;;;;;AAcR,IAAM,oCAAc,SAAd,WAAc,CAAC,IAAD,EAAuD;MAAhD,2EAAO,EAAE,SAAS,uBAAT,GAAuC;;AAChF,MAAM,IAAI,YAAY,IAAZ,CAAiB,IAAjB,EAAuB,IAAvB,EAA6B,IAA7B,CAAJ,CAD0E;AAEhF,WAAS,GAAT,CAAa,IAAb,EAAmB,CAAnB,EAFgF;AAGhF,SAAO,CAAP,CAHgF;CAAvD;;AAMpB,IAAM,oCAAc,SAAd,WAAc,CAAC,aAAD,EAAuC;MAAvB,iFAAa,MAAU;;yBACpC,gBAAgB,cAAc,OAAd;;MAApC;MAAM,iCADkD;;AAEhE,MAAI,CAAC,IAAD,EAAO,OAAO,aAAa,IAAb,GAAoB,aAApB,CAAlB;AACA,MAAM,cAAc,SAAS,GAAT,CAAa,IAAb,CAAd,CAH0D;AAIhE,MAAI,CAAC,WAAD,EAAc,OAAO,aAAa,IAAb,GAAoB,aAApB,CAAzB;AACA,MAAM,QAAQ,IAAI,WAAJ,CAAgB;AAC5B,wBAD4B;GAAhB,CAAR,CAL0D;AAQhE,SAAO,MAAM,SAAN,EAAP,CARgE;CAAvC","file":"index.js","sourcesContent":["import ExtendableError from 'es6-error';\n\nconst errorMap = new Map();\n\nconst DELIMITER = ':';\n\nconst serializeName = (arr = []) => arr.reduce((str, val) => `${str.length > 0 ? str + DELIMITER : str}${val}`, '');\nconst deserializeName = (name = '') => {\n const arr = [];\n const str = name.split(DELIMITER);\n arr.push(str.shift());\n arr.push(str.join(DELIMITER));\n return arr;\n};\n\nclass ApolloError extends ExtendableError {\n constructor (name, {\n message,\n time_thrown = (new Date()).toISOString(),\n data = {}\n }) {\n const t = (arguments[2] && arguments[2].thrown_at) || time_thrown;\n const d = Object.assign({}, data, ((arguments[2] && arguments[2].data) || {}));\n\n super(serializeName([\n name,\n t\n ]));\n\n this._name = name;\n this._humanized_message = message || '';\n this._time_thrown = t;\n this._data = d;\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 return {\n message,\n name,\n time_thrown,\n data\n };\n }\n}\n\nexport const createError = (name, data = { message: 'An error has occurred' }) => {\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 ] = deserializeName(originalError.message);\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 thrown_at\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","deserializeName","name","split","push","shift","join","ApolloError","message","time_thrown","Date","toISOString","data","t","arguments","thrown_at","d","Object","assign","_name","_humanized_message","_time_thrown","_data","createError","e","bind","set","formatError","originalError","returnNull","CustomError","get","error","serialize"],"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;;;AAEA,IAAMA,WAAW,IAAIC,GAAJ,EAAjB;;AAEA,IAAMC,YAAY,GAAlB;;AAEA,IAAMC,gBAAgB,SAAhBA,aAAgB;AAAA,MAACC,GAAD,uEAAO,EAAP;AAAA,SAAcA,IAAIC,MAAJ,CAAW,UAACC,GAAD,EAAMC,GAAN;AAAA,iBAAiBD,IAAIE,MAAJ,GAAa,CAAb,GAAiBF,MAAMJ,SAAvB,GAAmCI,GAApD,IAA0DC,GAA1D;AAAA,GAAX,EAA4E,EAA5E,CAAd;AAAA,CAAtB;AACA,IAAME,kBAAkB,SAAlBA,eA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EAAyC;;AAChF,MAAMgB,IAAIjB,YAAYkB,IAAZ,CAAiB,IAAjB,EAAuBvB,IAAvB,EAA6BU,IAA7B,CAAV;AACApB,WAASkC,GAAT,CAAaxB,IAAb,EAAmBsB,CAAnB;AACA,SAAOA,CAAP;AACD,CAJM;;AAMA,IAAMG,oCAAc,SAAdA,WAAc,CAACC,aAAD,EAAuC;AAAA,MAAvBC,UAAuB,uEAAV,KAAU;;AAAA,yBACpC5B,gBAAgB2B,cAAcpB,OAA9B,CADoC;AAAA;AAAA,MACxDN,IADwD;AAAA,MAClDa,SADkD;;AAEhE,MAAI,CAACb,IAAL,EAAW,OAAO2B,aAAa,IAAb,GAAoBD,aAA3B;AACX,MAAME,cAActC,SAASuC,GAAT,CAAa7B,IAAb,CAApB;AACA,MAAI,CAAC4B,WAAL,EAAkB,OAAOD,aAAa,IAAb,GAAoBD,aAA3B;AAClB,MAAMI,QAAQ,IAAIF,WAAJ,CAAgB;AAC5Bf;AAD4B,GAAhB,CAAd;AAGA,SAAOiB,MAAMC,SAAN,EAAP;AACD,CATM","file":"index.js","sourcesContent":["import ExtendableError from 'es6-error';\n\nconst errorMap = new Map();\n\nconst DELIMITER = ':';\n\nconst serializeName = (arr = []) => arr.reduce((str, val) => `${str.length > 0 ? str + DELIMITER : str}${val}`, '');\nconst deserializeName = (name = '') => {\n const arr = [];\n const str = name.split(DELIMITER);\n arr.push(str.shift());\n arr.push(str.join(DELIMITER));\n return arr;\n};\n\nclass ApolloError extends ExtendableError {\n constructor (name, {\n message,\n time_thrown = (new Date()).toISOString(),\n data = {}\n }) {\n const t = (arguments[2] && arguments[2].thrown_at) || time_thrown;\n const d = Object.assign({}, data, ((arguments[2] && arguments[2].data) || {}));\n\n super(serializeName([\n name,\n t\n ]));\n\n this._name = name;\n this._humanized_message = message || '';\n this._time_thrown = t;\n this._data = d;\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 return {\n message,\n name,\n time_thrown,\n data\n };\n }\n}\n\nexport const createError = (name, data = { message: 'An error has occurred' }) => {\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 ] = deserializeName(originalError.message);\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 thrown_at\n });\n return error.serialize();\n};\n"]} \ No newline at end of file diff --git a/test/spec.js b/test/spec.js index c6a5597..86d5488 100644 --- a/test/spec.js +++ b/test/spec.js @@ -23,7 +23,7 @@ describe('createError', () => { expect(message).to.equal('A foo error has occurred'); expect(name).to.equal('FooError'); - expect(time_thrown).to.equal(iso); + expect(time_thrown).to.equal(e._time_thrown); expect(data).to.eql({ hello: 'world', foo: 'bar'