* Rollback (abort) the transaction * * @returns {Promise}
()
| 79 | * @returns {Promise} |
| 80 | */ |
| 81 | async rollback() { |
| 82 | if (this.finished) { |
| 83 | throw new Error(`Transaction cannot be rolled back because it has been finished with state: ${this.finished}`); |
| 84 | } |
| 85 | |
| 86 | if (!this.connection) { |
| 87 | throw new Error('Transaction cannot be rolled back because it never started'); |
| 88 | } |
| 89 | |
| 90 | try { |
| 91 | await this |
| 92 | .sequelize |
| 93 | .getQueryInterface() |
| 94 | .rollbackTransaction(this, this.options); |
| 95 | |
| 96 | this.cleanup(); |
| 97 | } catch (e) { |
| 98 | console.warn(`Rolling back transaction ${this.id} failed with error ${JSON.stringify(e.message)}. We are killing its connection as it is now in an undetermined state.`); |
| 99 | await this.forceCleanup(); |
| 100 | |
| 101 | throw e; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Called to acquire a connection to use and set the correct options on the connection. |