Skip to content

Commit 4c8e637

Browse files
authored
chore: postman attachment size exceeded error (#796)
## Problem Currently, we don't check for attachment exceeded error for postman step. Postman [guide](https://postman-v1.guides.gov.sg/email-api-guide/programmatic-email-api/send-email-api/attachments) says that it is 2MB per attachment and 10MB in total, it seems like 2MB is a soft limit and the 413 error only throws when the attachments exceed 10MB in total. ![image](https://github.com/user-attachments/assets/23905adf-44b8-47d8-9b5f-7498f7d4da00) ## Solution Check for the specific error code: `attachment_limit` and throw step error for that. <img width="895" alt="image" src="https://github.com/user-attachments/assets/032a4a22-31b8-42a0-a0a9-77ce3a78b02f"> ## Tests - [x] Normal executions still work with postman - [x] Attachments under the size of 10 MB works although it's slow - [x] One attachment fails when it exceeds 10MB - [x] Multiple attachment fails when they exceed 10MB
1 parent 531c736 commit 4c8e637

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

packages/backend/src/apps/postman/common/data-out-validator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const dataOutSchema = z.object(
88
'BLACKLISTED',
99
'RATE-LIMITED',
1010
'INVALID-ATTACHMENT',
11+
'ATTACHMENT-SIZE-EXCEEDED',
1112
'INTERMITTENT-ERROR',
1213
'ERROR',
1314
]),

packages/backend/src/apps/postman/common/email-helper.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,16 @@ export async function sendTransactionalEmails(
159159
* Since we can only return one error per postman step, we have to select in terms of priority
160160
* 1. RATE-LIMITED (so we can auto-retry)
161161
* 2. INVALID-ATTACHMENT (probably all recipients should fail)
162-
* 3. INTERMITTENT-ERROR (some recipients failed, auto-retry)
163-
* 4. ERROR (probably all recipients should fail)
164-
* 5. BLACKLISTED (blacklisted errors are returned even if there are other errors like invalid attachment)
162+
* 3. ATTACHMENT-SIZE-EXCEEDED (probably all recipients should fail)
163+
* 4. INTERMITTENT-ERROR (some recipients failed, auto-retry)
164+
* 5. ERROR (probably all recipients should fail)
165+
* 6. BLACKLISTED (blacklisted errors are returned even if there are other errors like invalid attachment)
165166
*/
166167
const sortedErrors = sortBy(errors, (error) =>
167168
[
168169
'RATE-LIMITED',
169170
'INVALID-ATTACHMENT',
171+
'ATTACHMENT-SIZE-EXCEEDED',
170172
'INTERMITTENT-ERROR',
171173
'ERROR',
172174
'BLACKLISTED',

packages/backend/src/apps/postman/common/throw-errors.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export function getPostmanErrorStatus(
3636
}
3737
case 'rate_limit':
3838
return 'RATE-LIMITED'
39+
case 'attachment_limit':
40+
return 'ATTACHMENT-SIZE-EXCEEDED'
3941
default:
4042
if (POSTMAN_RETRIABLE_HTTP_CODES.includes(error.response?.status)) {
4143
return 'INTERMITTENT-ERROR'
@@ -105,6 +107,14 @@ export function throwPostmanStepError({
105107
appName,
106108
error,
107109
)
110+
case 'ATTACHMENT-SIZE-EXCEEDED':
111+
throw new StepError(
112+
'Total attachment size exceeded',
113+
'Click on set up action and check that the attachments do not exceed 10MB in total.',
114+
position,
115+
appName,
116+
error,
117+
)
108118
case 'INTERMITTENT-ERROR':
109119
throw new RetriableError({
110120
error: error.details,

0 commit comments

Comments
 (0)