Skip to content

Commit 2c180fd

Browse files
authored
feat: add TransactionRejected error (#104)
* feat: add TransactionRejected error * fix: error codes
1 parent d63a80b commit 2c180fd

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

src/utils/errors.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export enum LifiErrorCode {
2222
GasLimitError = 1009,
2323
SlippageNotMet = 1010,
2424
SlippageError = 1011,
25+
TransactionRejected = 1012,
2526
}
2627

2728
export enum MetaMaskRPCErrorCode {

src/utils/parseError.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import ChainsService from '../services/ChainsService'
77
import {
88
LifiError,
99
LifiErrorCode,
10+
MetaMaskProviderErrorCode,
1011
NotFoundError,
1112
ProviderError,
1213
RPCError,
@@ -152,40 +153,45 @@ export const parseError = async (
152153
)
153154
}
154155
}
156+
}
155157

156-
if (e.code === 'CALL_EXCEPTION') {
158+
switch (e.code) {
159+
case 'CALL_EXCEPTION':
157160
return new ProviderError(
158161
LifiErrorCode.TransactionFailed,
159162
e.reason,
160163
await getTransactionNotSentMessage(step, process),
161164
e.stack
162165
)
163-
}
164-
165-
if (e.code === LifiErrorCode.TransactionUnprepared) {
166+
case 'ACTION_REJECTED':
167+
case MetaMaskProviderErrorCode.userRejectedRequest:
168+
return new TransactionError(
169+
LifiErrorCode.TransactionRejected,
170+
e.message,
171+
await getTransactionNotSentMessage(step, process),
172+
e.stack
173+
)
174+
case LifiErrorCode.TransactionUnprepared:
166175
return new TransactionError(
167176
LifiErrorCode.TransactionUnprepared,
168177
e.message,
169178
await getTransactionNotSentMessage(step, process),
170179
e.stack
171180
)
172-
}
173-
174-
if (e.code === LifiErrorCode.ValidationError) {
181+
case LifiErrorCode.ValidationError:
175182
return new TransactionError(
176183
LifiErrorCode.ValidationError,
177184
e.message,
178185
e.htmlMessage
179186
)
180-
}
187+
default:
188+
return new UnknownError(
189+
LifiErrorCode.InternalError,
190+
e.message || 'Unknown error occurred.',
191+
undefined,
192+
e.stack
193+
)
181194
}
182-
183-
return new UnknownError(
184-
LifiErrorCode.InternalError,
185-
e.message || 'Unknown error occurred.',
186-
undefined,
187-
e.stack
188-
)
189195
}
190196

191197
export const parseBackendError = (e: any): LifiError => {

0 commit comments

Comments
 (0)