Skip to content

Commit 102773e

Browse files
committed
Improved logs to help clarify random timeouts with Amazon services
1 parent 9a5a677 commit 102773e

File tree

6 files changed

+57
-49
lines changed

6 files changed

+57
-49
lines changed

packages/analytics/index.mjs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,32 +62,36 @@ export const handler = async ({ body, headers } /*, context*/) => {
6262
return jsonResponse({ content: { message }, statusCode: 422 });
6363
}
6464

65-
console.log('Event sent:', await send(input));
65+
console.log('Result from Pinpoint:', await send(input));
6666

6767
return response({ statusCode: 204 });
6868
};
6969

7070
const jsonResponse = (config) =>
7171
response({ contentType: JSON_CONTENT_TYPE, ...config });
7272

73-
const response = ({ content, contentType, statusCode }) => ({
74-
...(content
75-
? {
76-
body:
77-
contentType === JSON_CONTENT_TYPE
78-
? JSON.stringify(content)
79-
: contentType === TEXT_CONTENT_TYPE
80-
? content
81-
: /* v8 ignore next */
82-
undefined, // TODO: https://github.com/tc39/proposal-throw-expressions
83-
}
84-
: {}),
85-
headers: {
86-
...CORS_HEADERS,
87-
...(contentType ? { [CONTENT_TYPE]: contentType } : {}),
88-
},
89-
statusCode,
90-
});
73+
const response = ({ content, contentType, statusCode }) => {
74+
const result = {
75+
...(content
76+
? {
77+
body:
78+
contentType === JSON_CONTENT_TYPE
79+
? JSON.stringify(content)
80+
: contentType === TEXT_CONTENT_TYPE
81+
? content
82+
: /* v8 ignore next */
83+
undefined, // TODO: https://github.com/tc39/proposal-throw-expressions
84+
}
85+
: {}),
86+
headers: {
87+
...CORS_HEADERS,
88+
...(contentType ? { [CONTENT_TYPE]: contentType } : {}),
89+
},
90+
statusCode,
91+
};
92+
console.log('Response:', result);
93+
return result;
94+
};
9195

9296
const send = ({ event, timestamp, ...attributes }) => {
9397
const config = {
@@ -108,7 +112,7 @@ const send = ({ event, timestamp, ...attributes }) => {
108112
},
109113
};
110114
console.log(
111-
'PutEventsCommand',
115+
'Sending to Pinpoint:',
112116
inspect(config, { depth: null, colors: false })
113117
);
114118
return new PinpointClient({ region: 'us-east-1' }).send(

packages/analytics/index.test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,6 @@ describe('Success response', () => {
597597
await expect(callHandler()).resolves.toMatchObject(
598598
createResponse({ statusCode: 204 })
599599
);
600-
expect(console.log).toHaveBeenCalledTimes(3);
600+
expect(console.log).toHaveBeenCalledTimes(4);
601601
});
602602
});

packages/analytics/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "analytics",
4-
"version": "1.0.0",
4+
"version": "1.0.1",
55
"main": "bundle.js",
66
"scripts": {
77
"build": "rm -f bundle.zip && esbuild index.mjs --bundle --minify --platform=node --outfile=bundle/bundle.js --sourcemap && cp package.json bundle/ && zip -r bundle.zip bundle/ && rm -rf bundle",

packages/email/index.mjs

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export const handler = async (
120120
}
121121

122122
console.log(
123-
'Email sent:',
123+
'Result from SES:',
124124
await send(WEBSITE_HOSTNAME, EMAIL_ADDRESS, {
125125
email: input.email,
126126
message: input.message,
@@ -138,27 +138,31 @@ export const handler = async (
138138
}
139139
};
140140

141-
const response = ({ content, contentType, redirect, statusCode }) => ({
142-
...(content
143-
? {
144-
body:
145-
contentType === FORM_CONTENT_TYPE
146-
? new URLSearchParams(content).toString()
147-
: contentType === JSON_CONTENT_TYPE
148-
? JSON.stringify(content)
149-
: contentType === TEXT_CONTENT_TYPE
150-
? content
151-
: /* v8 ignore next */
152-
undefined, // TODO: https://github.com/tc39/proposal-throw-expressions
153-
}
154-
: {}),
155-
headers: {
156-
...CORS_HEADERS,
157-
...(contentType ? { [CONTENT_TYPE]: contentType } : {}),
158-
...(redirect ? { Location: new URL(redirect, WEBSITE_URL).href } : {}),
159-
},
160-
statusCode,
161-
});
141+
const response = ({ content, contentType, redirect, statusCode }) => {
142+
const result = {
143+
...(content
144+
? {
145+
body:
146+
contentType === FORM_CONTENT_TYPE
147+
? new URLSearchParams(content).toString()
148+
: contentType === JSON_CONTENT_TYPE
149+
? JSON.stringify(content)
150+
: contentType === TEXT_CONTENT_TYPE
151+
? content
152+
: /* v8 ignore next */
153+
undefined, // TODO: https://github.com/tc39/proposal-throw-expressions
154+
}
155+
: {}),
156+
headers: {
157+
...CORS_HEADERS,
158+
...(contentType ? { [CONTENT_TYPE]: contentType } : {}),
159+
...(redirect ? { Location: new URL(redirect, WEBSITE_URL).href } : {}),
160+
},
161+
statusCode,
162+
};
163+
console.log('Response:', result);
164+
return result;
165+
};
162166

163167
const formResponse = (config) =>
164168
response({ contentType: FORM_CONTENT_TYPE, ...config });
@@ -196,7 +200,7 @@ const send = (websiteName, targetEmail, { email, message, name }) => {
196200
},
197201
};
198202
console.log(
199-
'SendEmailCommand',
203+
'Sending to SES:',
200204
inspect(config, { depth: null, colors: false })
201205
);
202206
return new SESClient({ region: 'us-east-1' }).send(

packages/email/index.test.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -615,14 +615,14 @@ describe('Success response', () => {
615615
await expect(
616616
callHandler({ contentType: JSON_CONTENT_TYPE })
617617
).resolves.toMatchObject(createResponse({ statusCode: 204 }));
618-
expect(console.log).toHaveBeenCalledTimes(4);
618+
expect(console.log).toHaveBeenCalledTimes(5);
619619
});
620620

621621
it(`is HTTP 204 when there's no "redirect" field for ${FORM_CONTENT_TYPE}`, async () => {
622622
await expect(
623623
callHandler({ contentType: FORM_CONTENT_TYPE })
624624
).resolves.toMatchObject(createResponse({ statusCode: 204 }));
625-
expect(console.log).toHaveBeenCalledTimes(4);
625+
expect(console.log).toHaveBeenCalledTimes(5);
626626
});
627627

628628
it(`redirects (HTTP 302) when there's a "redirect" field for ${FORM_CONTENT_TYPE}`, async () => {
@@ -634,6 +634,6 @@ describe('Success response', () => {
634634
statusCode: 302,
635635
})
636636
);
637-
expect(console.log).toHaveBeenCalledTimes(4);
637+
expect(console.log).toHaveBeenCalledTimes(5);
638638
});
639639
});

packages/email/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "email",
4-
"version": "1.0.0",
4+
"version": "1.0.1",
55
"main": "bundle.js",
66
"scripts": {
77
"build": "rm -f bundle.zip && esbuild index.mjs --bundle --minify --platform=node --outfile=bundle/bundle.js --sourcemap && cp package.json bundle/ && zip -r bundle.zip bundle/ && rm -rf bundle",

0 commit comments

Comments
 (0)