Skip to content

Instantly share code, notes, and snippets.

@riandesign
Created October 3, 2019 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riandesign/10daf98a45422b688538410eb29d29a5 to your computer and use it in GitHub Desktop.
Save riandesign/10daf98a45422b688538410eb29d29a5 to your computer and use it in GitHub Desktop.
{"error":{"message":"Validation error","name":"SequelizeUniqueConstraintError","frames":[{"file":"node_modules/sequelize/lib/dialects/mysql/query.js","filePath":"/Users/riandutra/Library/Mobile Documents/com~apple~CloudDocs/Projects/EveryUX/Dev/everyux_api/node_modules/sequelize/lib/dialects/mysql/query.js","method":"Query.formatError","line":223,"column":16,"context":{"start":218,"pre":" this.instance,\n 'not_unique'\n ));\n });\n","line":" return new sequelizeErrors.UniqueConstraintError({ message, errors, parent: err, fields });","post":" }\n\n case 1451:\n case 1452: {\n // e.g. CONSTRAINT `example_constraint_name` FOREIGN KEY (`example_id`) REFERENCES `examples` (`id`)"},"isModule":true,"isNative":false,"isApp":false},{"file":"node_modules/sequelize/lib/dialects/mysql/query.js","filePath":"/Users/riandutra/Library/Mobile Documents/com~apple~CloudDocs/Projects/EveryUX/Dev/everyux_api/node_modules/sequelize/lib/dialects/mysql/query.js","method":"Execute.handler [as onResult]","line":51,"column":23,"context":{"start":46,"pre":" options.transaction.finished = 'rollback';\n }\n err.sql = sql;\n err.parameters = parameters;\n","line":" reject(this.formatError(err));","post":" } else {\n resolve(results);\n }\n };\n if (parameters) {"},"isModule":true,"isNative":false,"isApp":false},{"file":"node_modules/mysql2/lib/commands/command.js","filePath":"/Users/riandutra/Library/Mobile Documents/com~apple~CloudDocs/Projects/EveryUX/Dev/everyux_api/node_modules/mysql2/lib/commands/command.js","method":"Execute.execute","line":30,"column":14,"context":{"start":25,"pre":" connection._resetSequenceId();\n }\n if (packet && packet.isError()) {\n const err = packet.asError(connection.clientEncoding);\n if (this.onResult) {","line":" this.onResult(err);","post":" this.emit('end');\n } else {\n this.emit('error', err);\n this.emit('end');\n }"},"isModule":true,"isNative":false,"isApp":false},{"file":"node_modules/mysql2/lib/connection.js","filePath":"/Users/riandutra/Library/Mobile Documents/com~apple~CloudDocs/Projects/EveryUX/Dev/everyux_api/node_modules/mysql2/lib/connection.js","method":"Connection.handlePacket","line":408,"column":32,"context":{"start":403,"pre":" 'PROTOCOL_UNEXPECTED_PACKET'\n );\n this.close();\n return;\n }","line":" const done = this._command.execute(packet, this);","post":" if (done) {\n this._command = this._commands.shift();\n if (this._command) {\n this.sequenceId = 0;\n this.compressedSequenceId = 0;"},"isModule":true,"isNative":false,"isApp":false},{"file":"node_modules/mysql2/lib/connection.js","filePath":"/Users/riandutra/Library/Mobile Documents/com~apple~CloudDocs/Projects/EveryUX/Dev/everyux_api/node_modules/mysql2/lib/connection.js","method":"PacketParser.Connection.packetParser.p [as onPacket]","line":70,"column":12,"context":{"start":65,"pre":" this._outOfOrderPackets = [];\n this.clientEncoding = CharsetToEncoding[this.config.charsetNumber];\n this.stream.on('error', this._handleNetworkError.bind(this));\n // see https://gist.github.com/khoomeister/4985691#use-that-instead-of-bind\n this.packetParser = new PacketParser(p => {","line":" this.handlePacket(p);","post":" });\n this.stream.on('data', data => {\n if (this.connectTimeout) {\n Timers.clearTimeout(this.connectTimeout);\n this.connectTimeout = null;"},"isModule":true,"isNative":false,"isApp":false},{"file":"node_modules/mysql2/lib/packet_parser.js","filePath":"/Users/riandutra/Library/Mobile Documents/com~apple~CloudDocs/Projects/EveryUX/Dev/everyux_api/node_modules/mysql2/lib/packet_parser.js","method":"PacketParser.executeStart","line":75,"column":16,"context":{"start":70,"pre":" const sequenceId = chunk[start + 3];\n if (\n this.length < MAX_PACKET_LENGTH &&\n this.largePacketParts.length === 0\n ) {","line":" this.onPacket(","post":" new Packet(\n sequenceId,\n chunk,\n start,\n start + this.packetHeaderLength + this.length"},"isModule":true,"isNative":false,"isApp":false},{"file":"node_modules/mysql2/lib/connection.js","filePath":"/Users/riandutra/Library/Mobile Documents/com~apple~CloudDocs/Projects/EveryUX/Dev/everyux_api/node_modules/mysql2/lib/connection.js","method":"Socket.Connection.stream.on.data","line":77,"column":25,"context":{"start":72,"pre":" this.stream.on('data', data => {\n if (this.connectTimeout) {\n Timers.clearTimeout(this.connectTimeout);\n this.connectTimeout = null;\n }","line":" this.packetParser.execute(data);","post":" });\n this.stream.on('close', () => {\n // we need to set this flag everywhere where we want connection to close\n if (this._closing) {\n return;"},"isModule":true,"isNative":false,"isApp":false},{"file":"events.js","filePath":"events.js","method":"Socket.emit","line":198,"column":13,"context":{},"isModule":false,"isNative":true,"isApp":false},{"file":"_stream_readable.js","filePath":"_stream_readable.js","method":"addChunk","line":288,"column":12,"context":{},"isModule":false,"isNative":true,"isApp":false},{"file":"_stream_readable.js","filePath":"_stream_readable.js","method":"readableAddChunk","line":269,"column":11,"context":{},"isModule":false,"isNative":true,"isApp":false},{"file":"_stream_readable.js","filePath":"_stream_readable.js","method":"Socket.Readable.push","line":224,"column":10,"context":{},"isModule":false,"isNative":true,"isApp":false},{"file":"internal/stream_base_commons.js","filePath":"internal/stream_base_commons.js","method":"TCP.onStreamRead [as onread]","line":94,"column":17,"context":{},"isModule":false,"isNative":true,"isApp":false},{"file":"node_modules/sequelize/lib/dialects/mysql/query.js","filePath":"/Users/riandutra/Library/Mobile Documents/com~apple~CloudDocs/Projects/EveryUX/Dev/everyux_api/node_modules/sequelize/lib/dialects/mysql/query.js","method":"Query.run","line":39,"column":12,"context":{"start":34,"pre":" //do we need benchmark for this query execution\n const showWarnings = this.sequelize.options.showWarnings || options.showWarnings;\n\n const complete = this._logQuery(sql, debug);\n","line":" return new Utils.Promise((resolve, reject) => {","post":" const handler = (err, results) => {\n complete();\n\n if (err) {\n // MySQL automatically rolls-back transactions in the event of a deadlock"},"isModule":true,"isNative":false,"isApp":false},{"file":"node_modules/sequelize/lib/sequelize.js","filePath":"/Users/riandutra/Library/Mobile Documents/com~apple~CloudDocs/Projects/EveryUX/Dev/everyux_api/node_modules/sequelize/lib/sequelize.js","method":"runHooks.then.then","line":643,"column":29,"context":{"start":638,"pre":" : this.connectionManager.getConnection(options);\n }).then(connection => {\n const query = new this.dialect.Query(connection, this, options);\n return this.runHooks('beforeQuery', options, query)\n .then(() => checkTransaction())","line":" .then(() => query.run(sql, bindParameters))","post":" .finally(() => this.runHooks('afterQuery', options, query))\n .finally(() => {\n if (!options.transaction) {\n return this.connectionManager.releaseConnection(connection);\n }"},"isModule":true,"isNative":false,"isApp":false},{"file":"node_modules/sequelize/lib/sequelize.js","filePath":"/Users/riandutra/Library/Mobile Documents/com~apple~CloudDocs/Projects/EveryUX/Dev/everyux_api/node_modules/sequelize/lib/sequelize.js","method":"Promise.try.then.connection","line":643,"column":12,"context":{"start":638,"pre":" : this.connectionManager.getConnection(options);\n }).then(connection => {\n const query = new this.dialect.Query(connection, this, options);\n return this.runHooks('beforeQuery', options, query)\n .then(() => checkTransaction())","line":" .then(() => query.run(sql, bindParameters))","post":" .finally(() => this.runHooks('afterQuery', options, query))\n .finally(() => {\n if (!options.transaction) {\n return this.connectionManager.releaseConnection(connection);\n }"},"isModule":true,"isNative":false,"isApp":false},{"file":"node_modules/sequelize/lib/sequelize.js","filePath":"/Users/riandutra/Library/Mobile Documents/com~apple~CloudDocs/Projects/EveryUX/Dev/everyux_api/node_modules/sequelize/lib/sequelize.js","method":"Promise.resolve.retry","line":639,"column":10,"context":{"start":634,"pre":" checkTransaction();\n\n return options.transaction\n ? options.transaction.connection\n : this.connectionManager.getConnection(options);","line":" }).then(connection => {","post":" const query = new this.dialect.Query(connection, this, options);\n return this.runHooks('beforeQuery', options, query)\n .then(() => checkTransaction())\n .then(() => query.run(sql, bindParameters))\n .finally(() => this.runHooks('afterQuery', options, query))"},"isModule":true,"isNative":false,"isApp":false},{"file":"node_modules/retry-as-promised/index.js","filePath":"/Users/riandutra/Library/Mobile Documents/com~apple~CloudDocs/Projects/EveryUX/Dev/everyux_api/node_modules/retry-as-promised/index.js","method":null,"line":70,"column":21,"context":{"start":65,"pre":" if (backoffTimeout) clearTimeout(backoffTimeout);\n reject(new TimeoutError(options.name + ' timed out', lastError));\n }, options.timeout);\n }\n","line":" Promise.resolve(callback({ current: options.$current }))","post":" .then(resolve)\n .then(function() {\n if (timeout) clearTimeout(timeout);\n if (backoffTimeout) clearTimeout(backoffTimeout);\n })"},"isModule":true,"isNative":false,"isApp":false},{"file":"node_modules/retry-as-promised/index.js","filePath":"/Users/riandutra/Library/Mobile Documents/com~apple~CloudDocs/Projects/EveryUX/Dev/everyux_api/node_modules/retry-as-promised/index.js","method":"retryAsPromised","line":60,"column":10,"context":{"start":55,"pre":" };\n\n if (!Array.isArray(options.match)) options.match = [options.match];\n options.report('Trying ' + options.name + ' #' + options.$current + ' at ' + new Date().toLocaleTimeString(), options);\n","line":" return new Promise(function(resolve, reject) {","post":" var timeout, backoffTimeout, lastError;\n\n if (options.timeout) {\n timeout = setTimeout(function() {\n if (backoffTimeout) clearTimeout(backoffTimeout);"},"isModule":true,"isNative":false,"isApp":false},{"file":"node_modules/sequelize/lib/sequelize.js","filePath":"/Users/riandutra/Library/Mobile Documents/com~apple~CloudDocs/Projects/EveryUX/Dev/everyux_api/node_modules/sequelize/lib/sequelize.js","method":"Promise.try","line":629,"column":30,"context":{"start":624,"pre":" }\n };\n\n const retryOptions = Object.assign({}, this.options.retry, options.retry || {});\n","line":" return Promise.resolve(retry(() => Promise.try(() => {","post":" if (options.transaction === undefined && Sequelize._cls) {\n options.transaction = Sequelize._cls.get('transaction');\n }\n\n checkTransaction();"},"isModule":true,"isNative":false,"isApp":false},{"file":"node_modules/sequelize/lib/sequelize.js","filePath":"/Users/riandutra/Library/Mobile Documents/com~apple~CloudDocs/Projects/EveryUX/Dev/everyux_api/node_modules/sequelize/lib/sequelize.js","method":"Sequelize.query","line":578,"column":23,"context":{"start":573,"pre":" //if user wants to always prepend searchPath (dialectOptions.preprendSearchPath = true)\n //then set to DEFAULT if none is provided\n options.searchPath = 'DEFAULT';\n }\n","line":" return Promise.try(() => {","post":" if (typeof sql === 'object') {\n if (sql.values !== undefined) {\n if (options.replacements !== undefined) {\n throw new Error('Both `sql.values` and `options.replacements` cannot be set at the same time');\n }"},"isModule":true,"isNative":false,"isApp":false},{"file":"node_modules/sequelize/lib/query-interface.js","filePath":"/Users/riandutra/Library/Mobile Documents/com~apple~CloudDocs/Projects/EveryUX/Dev/everyux_api/node_modules/sequelize/lib/query-interface.js","method":"QueryInterface.insert","line":885,"column":27,"context":{"start":880,"pre":" const sql = this.QueryGenerator.insertQuery(tableName, values, instance && instance.constructor.rawAttributes, options);\n\n options.type = QueryTypes.INSERT;\n options.instance = instance;\n","line":" return this.sequelize.query(sql, options).then(results => {","post":" if (instance) results[0].isNewRecord = false;\n return results;\n });\n }\n"},"isModule":true,"isNative":false,"isApp":false},{"file":"node_modules/sequelize/lib/model.js","filePath":"/Users/riandutra/Library/Mobile Documents/com~apple~CloudDocs/Projects/EveryUX/Dev/everyux_api/node_modules/sequelize/lib/model.js","method":"Promise.try.then.then.then","line":3987,"column":52,"context":{"start":3982,"pre":" }\n query = 'update';\n args = [this, this.constructor.getTableName(options), values, where, options];\n }\n","line":" return this.constructor.QueryInterface[query](...args)","post":" .then(([result, rowsUpdated])=> {\n if (versionAttr) {\n // Check to see that a row was updated, otherwise it's an optimistic locking error.\n if (rowsUpdated < 1) {\n throw new sequelizeErrors.OptimisticLockError({"},"isModule":true,"isNative":false,"isApp":false},{"file":"timers.js","filePath":"timers.js","method":"runCallback","line":705,"column":18,"context":{},"isModule":false,"isNative":true,"isApp":false},{"file":"timers.js","filePath":"timers.js","method":"tryOnImmediate","line":676,"column":5,"context":{},"isModule":false,"isNative":true,"isApp":false},{"file":"timers.js","filePath":"timers.js","method":"processImmediate","line":658,"column":5,"context":{},"isModule":false,"isNative":true,"isApp":false},{"file":"node_modules/sequelize/lib/model.js","filePath":"/Users/riandutra/Library/Mobile Documents/com~apple~CloudDocs/Projects/EveryUX/Dev/everyux_api/node_modules/sequelize/lib/model.js","method":"User.save","line":3964,"column":8,"context":{"start":3959,"pre":" parentRecord: this\n }).value();\n\n return instance.save(includeOptions).then(() => this[include.association.accessors.set](instance, { save: false, logging: options.logging }));\n });","line":" }).then(() => {","post":" const realFields = options.fields.filter(field => !this.constructor._virtualAttributes.has(field));\n if (!realFields.length) return this;\n if (!this.changed() && !this.isNewRecord) return this;\n\n const versionFieldName = _.get(this.constructor.rawAttributes[versionAttr], 'field') || versionAttr;"},"isModule":true,"isNative":false,"isApp":false},{"file":"node_modules/sequelize/lib/model.js","filePath":"/Users/riandutra/Library/Mobile Documents/com~apple~CloudDocs/Projects/EveryUX/Dev/everyux_api/node_modules/sequelize/lib/model.js","method":"Function.create","line":2225,"column":8,"context":{"start":2220,"pre":" isNewRecord: true,\n attributes: options.fields,\n include: options.include,\n raw: options.raw,\n silent: options.silent","line":" }).save(options);","post":" }\n\n /**\n * Find a row that matches the query, or build (but don't save) the row if none is found.\n * The successful result of the promise will be (instance, built)"},"isModule":true,"isNative":false,"isApp":false},{"file":"src/app/controllers/UserController.js","filePath":"/Users/riandutra/Library/Mobile Documents/com~apple~CloudDocs/Projects/EveryUX/Dev/everyux_api/src/app/controllers/UserController.js","method":"store","line":40,"column":54,"context":{"start":35,"pre":" });\n if (userAlreadExists) {\n return res.status(400).json({ error: 'email.alread.registered' });\n }\n","line":" const { id, name, email } = await User.create({","post":" ...req.body,\n createdby_id: req.userId,\n });\n\n return res.json({ id, name, email });"},"isModule":false,"isNative":false,"isApp":true}]}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment