Skip to content
This repository was archived by the owner on May 28, 2021. It is now read-only.

Commit 202f704

Browse files
committed
rewrite logic for async await
1 parent 746a0d4 commit 202f704

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

functions/register.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,29 @@ exports.handler = async function(event) {
77

88
if (!name || !city) {
99
console.error(err)
10-
return
10+
return {
11+
statusCode: 500,
12+
body: `Something went wrong. Double check if you sent a valid name and city.`
13+
}
1114
}
1215

1316
try {
14-
await base(process.env.AIRTABLE_TABLE).create(
15-
{
17+
return await base(process.env.AIRTABLE_TABLE)
18+
.create({
1619
name: name,
1720
city: city,
1821
ghLink: github
19-
},
20-
(err, record) => {
21-
if (err) {
22-
console.error(err)
23-
return
22+
})
23+
.then(record => {
24+
return {
25+
statusCode: 200,
26+
body: `Successfully added ${event.queryStringParameters.name}. document ID is ${record.id}`
2427
}
25-
console.log(`Human was created, document ID is ${record.getId()}`)
26-
}
27-
)
28-
return {
29-
statusCode: 200,
30-
body: `Successfully added ${event.queryStringParameters.name}`
31-
}
32-
} catch (err) {
28+
})
29+
} catch {
3330
return {
3431
statusCode: 500,
35-
body: JSON.stringify(err.message)
32+
body: `Something went wrong`
3633
}
3734
}
3835
}

0 commit comments

Comments
 (0)