forked from safe-global/safe-client-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Throw custom errors from relayer (safe-global#1154)
This adds custom errors for the following to the relayer: - Invalid `multiSend` - Invalid transfers - Unofficial mastercopies - Unofficial MultiSend contracts
- Loading branch information
Showing
12 changed files
with
223 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class InvalidMultiSendError extends Error { | ||
constructor() { | ||
super( | ||
'Invalid multiSend call. The batch is not all execTransaction calls to same address.', | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class InvalidTransferError extends Error { | ||
constructor() { | ||
super( | ||
'Invalid transfer. The proposed transfer is not an execTransaction, multiSend, or createProxyWithNonce call.', | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class UnofficialMasterCopyError extends Error { | ||
constructor() { | ||
super( | ||
'Safe attempting to relay is not official. Only official Safe singletons are supported.', | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class UnofficialMultiSendError extends Error { | ||
constructor() { | ||
super( | ||
'MultiSend contract is not official. Only official MultiSend contracts are supported.', | ||
); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/domain/relay/exception-filters/invalid-multisend.exception-filter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Response } from 'express'; | ||
import { | ||
Catch, | ||
ExceptionFilter, | ||
ArgumentsHost, | ||
HttpStatus, | ||
} from '@nestjs/common'; | ||
import { InvalidMultiSendError } from '@/domain/relay/errors/invalid-multisend.error'; | ||
|
||
@Catch(InvalidMultiSendError) | ||
export class InvalidMultiSendExceptionFilter implements ExceptionFilter { | ||
catch(error: InvalidMultiSendError, host: ArgumentsHost): void { | ||
const ctx = host.switchToHttp(); | ||
const response = ctx.getResponse<Response>(); | ||
|
||
response.status(HttpStatus.UNPROCESSABLE_ENTITY).json({ | ||
message: error.message, | ||
statusCode: HttpStatus.UNPROCESSABLE_ENTITY, | ||
}); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/domain/relay/exception-filters/invalid-transfer.exception-filter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Response } from 'express'; | ||
import { | ||
Catch, | ||
ExceptionFilter, | ||
ArgumentsHost, | ||
HttpStatus, | ||
} from '@nestjs/common'; | ||
import { InvalidTransferError } from '@/domain/relay/errors/invalid-transfer.error'; | ||
|
||
@Catch(InvalidTransferError) | ||
export class InvalidTransferExceptionFilter implements ExceptionFilter { | ||
catch(error: InvalidTransferError, host: ArgumentsHost): void { | ||
const ctx = host.switchToHttp(); | ||
const response = ctx.getResponse<Response>(); | ||
|
||
response.status(HttpStatus.UNPROCESSABLE_ENTITY).json({ | ||
message: error.message, | ||
statusCode: HttpStatus.UNPROCESSABLE_ENTITY, | ||
}); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/domain/relay/exception-filters/unofficial-master-copy.exception-filter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Response } from 'express'; | ||
import { | ||
Catch, | ||
ExceptionFilter, | ||
ArgumentsHost, | ||
HttpStatus, | ||
} from '@nestjs/common'; | ||
import { UnofficialMasterCopyError } from '@/domain/relay/errors/unofficial-master-copy.error'; | ||
|
||
@Catch(UnofficialMasterCopyError) | ||
export class UnofficialMasterCopyExceptionFilter implements ExceptionFilter { | ||
catch(_: UnofficialMasterCopyError, host: ArgumentsHost): void { | ||
const ctx = host.switchToHttp(); | ||
const response = ctx.getResponse<Response>(); | ||
|
||
response.status(HttpStatus.UNPROCESSABLE_ENTITY).json({ | ||
message: 'Unsupported base contract.', | ||
statusCode: HttpStatus.UNPROCESSABLE_ENTITY, | ||
}); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/domain/relay/exception-filters/unofficial-multisend.error.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Response } from 'express'; | ||
import { | ||
Catch, | ||
ExceptionFilter, | ||
ArgumentsHost, | ||
HttpStatus, | ||
} from '@nestjs/common'; | ||
import { UnofficialMultiSendError } from '@/domain/relay/errors/unofficial-multisend.error'; | ||
|
||
@Catch(UnofficialMultiSendError) | ||
export class UnofficialMultiSendExceptionFilter implements ExceptionFilter { | ||
catch(_: UnofficialMultiSendError, host: ArgumentsHost): void { | ||
const ctx = host.switchToHttp(); | ||
const response = ctx.getResponse<Response>(); | ||
|
||
response.status(HttpStatus.UNPROCESSABLE_ENTITY).json({ | ||
message: 'Unofficial MultiSend contract.', | ||
statusCode: HttpStatus.UNPROCESSABLE_ENTITY, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.