{"action":"opened","issue":{"url":"https://api.github.com/repos/NullEnt1ty/nestjs-typeorm-example/issues/4","repository_url":"https://api.github.com/repos/NullEnt1ty/nestjs-typeorm-example","labels_url":"https://api.github.com/repos/NullEnt1ty/nestjs-typeorm-example/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/NullEnt1ty/nestjs-typeorm-example/issues/4/comments","events_url":"https://api.github.com/repos/NullEnt1ty/nestjs-typeorm-example/issues/4/events","html_url":"https://github.com/NullEnt1ty/nestjs-typeorm-example/issues/4","id":393739834,"node_id":"MDU6SXNzdWUzOTM3Mzk4MzQ=","number":4,"title":"Find good way to avoid duplicate key errors","user":{"login":"NullEnt1ty","id":966433,"node_id":"MDQ6VXNlcjk2NjQzMw==","avatar_url":"https://avatars1.githubusercontent.com/u/966433?v=4","gravatar_id":"","url":"https://api.github.com/users/NullEnt1ty","html_url":"https://github.com/NullEnt1ty","followers_url":"https://api.github.com/users/NullEnt1ty/followers","following_url":"https://api.github.com/users/NullEnt1ty/following{/other_user}","gists_url":"https://api.github.com/users/NullEnt1ty/gists{/gist_id}","starred_url":"https://api.github.com/users/NullEnt1ty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NullEnt1ty/subscriptions","organizations_url":"https://api.github.com/users/NullEnt1ty/orgs","repos_url":"https://api.github.com/users/NullEnt1ty/repos","events_url":"https://api.github.com/users/NullEnt1ty/events{/privacy}","received_events_url":"https://api.github.com/users/NullEnt1ty/received_events","type":"User","site_admin":false},"labels":[{"id":1169850603,"node_id":"MDU6TGFiZWwxMTY5ODUwNjAz","url":"https://api.github.com/repos/NullEnt1ty/nestjs-typeorm-example/labels/enhancement","name":"enhancement","color":"a2eeef","default":true}],"state":"open","locked":false,"assignee":{"login":"NullEnt1ty","id":966433,"node_id":"MDQ6VXNlcjk2NjQzMw==","avatar_url":"https://avatars1.githubusercontent.com/u/966433?v=4","gravatar_id":"","url":"https://api.github.com/users/NullEnt1ty","html_url":"https://github.com/NullEnt1ty","followers_url":"https://api.github.com/users/NullEnt1ty/followers","following_url":"https://api.github.com/users/NullEnt1ty/following{/other_user}","gists_url":"https://api.github.com/users/NullEnt1ty/gists{/gist_id}","starred_url":"https://api.github.com/users/NullEnt1ty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NullEnt1ty/subscriptions","organizations_url":"https://api.github.com/users/NullEnt1ty/orgs","repos_url":"https://api.github.com/users/NullEnt1ty/repos","events_url":"https://api.github.com/users/NullEnt1ty/events{/privacy}","received_events_url":"https://api.github.com/users/NullEnt1ty/received_events","type":"User","site_admin":false},"assignees":[{"login":"NullEnt1ty","id":966433,"node_id":"MDQ6VXNlcjk2NjQzMw==","avatar_url":"https://avatars1.githubusercontent.com/u/966433?v=4","gravatar_id":"","url":"https://api.github.com/users/NullEnt1ty","html_url":"https://github.com/NullEnt1ty","followers_url":"https://api.github.com/users/NullEnt1ty/followers","following_url":"https://api.github.com/users/NullEnt1ty/following{/other_user}","gists_url":"https://api.github.com/users/NullEnt1ty/gists{/gist_id}","starred_url":"https://api.github.com/users/NullEnt1ty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NullEnt1ty/subscriptions","organizations_url":"https://api.github.com/users/NullEnt1ty/orgs","repos_url":"https://api.github.com/users/NullEnt1ty/repos","events_url":"https://api.github.com/users/NullEnt1ty/events{/privacy}","received_events_url":"https://api.github.com/users/NullEnt1ty/received_events","type":"User","site_admin":false}],"milestone":null,"comments":0,"created_at":"2018-12-23T10:40:06Z","updated_at":"2018-12-23T10:40:06Z","closed_at":null,"author_association":"OWNER","body":"When you try to insert an already existing user (`username` and `email` are unique contraints) the database throws an error:\r\n\r\n```\r\nQueryFailedError: Duplicate entry 'my_username' for key 'IDX_78a916df40e02a9deb1c4b75ed'\r\n    at new QueryFailedError (/home/dominique/Documents/projects/nestjs-typeorm-example/src/error/QueryFailedError.ts:9:9)\r\n    at Query.onResult (/home/dominique/Documents/projects/nestjs-typeorm-example/src/driver/mysql/MysqlQueryRunner.ts:163:37)\r\n    at Query.execute (/home/dominique/Documents/projects/nestjs-typeorm-example/node_modules/mysql2/lib/commands/command.js:30:14)\r\n    at PoolConnection.handlePacket (/home/dominique/Documents/projects/nestjs-typeorm-example/node_modules/mysql2/lib/connection.js:455:32)\r\n    at PacketParser.onPacket (/home/dominique/Documents/projects/nestjs-typeorm-example/node_modules/mysql2/lib/connection.js:73:18)\r\n    at PacketParser.executeStart (/home/dominique/Documents/projects/nestjs-typeorm-example/node_modules/mysql2/lib/packet_parser.js:75:16)\r\n    at Socket.<anonymous> (/home/dominique/Documents/projects/nestjs-typeorm-example/node_modules/mysql2/lib/connection.js:80:31)\r\n    at Socket.emit (events.js:182:13)\r\n    at Socket.EventEmitter.emit (domain.js:442:20)\r\n    at addChunk (_stream_readable.js:283:12)\r\n```\r\n\r\nThe goal ist to find a good way to avoid these errors.\r\n\r\n- Query the database before attempting to insert the user?\r\n- Catch the error and try to parse it (that feels shabby)?"}}
{"actor":{"display_login":"NullEnt1ty"}}