Skip to content

Commit 092f5c1

Browse files
authored
Update index.js
1 parent 90dbc30 commit 092f5c1

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

src/index.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,35 @@ router.use((req, res, next) => {
2525

2626
router.post('/lambda/json-to-excel/styled', async (req, res) => {
2727
console.log('styled working')
28-
const jsonData = req.body.excel
29-
const defaultStyle = req.body.config.default_style
30-
const excelData = await convertJsonToStyledExcel(jsonData, defaultStyle)
31-
const url = await uploadToAWS(req.body.config, excelData)
32-
return res.json({ url })
28+
try {
29+
const jsonData = req.body.excel
30+
const defaultStyle = req.body.config.default_style
31+
const excelData = await convertJsonToStyledExcel(jsonData, defaultStyle)
32+
const url = await uploadToAWS(req.body.config, excelData)
33+
return res.json({ url })
34+
} catch (error) {
35+
console.log('error', error)
36+
res.status(400).json({ message: 'error in your request payload', error: error.message, rawError: error })
37+
}
3338
})
3439

35-
router.post('/styled', async (req, res) => {
36-
console.log('styled not working form infra side')
37-
return res.json({ message: "jsonToStyledExcel" })
38-
})
3940

4041
router.post('/api/jsonToExcel', async (req, res) => {
41-
console.log('old path')
42-
const jsonData = req.body.excel
43-
const excelData = await convertJsonToExcel(jsonData)
44-
const link = await uploadToAWS(req.body.config, excelData)
45-
46-
return res.json(link)
42+
try {
43+
console.log('old path')
44+
const jsonData = req.body.excel
45+
const excelData = await convertJsonToExcel(jsonData)
46+
const link = await uploadToAWS(req.body.config, excelData)
47+
return res.json(link)
48+
} catch (error) {
49+
console.log('error', error)
50+
res.status(400).json({ message: 'error in your request payload', error: error.message, rawError: error })
51+
}
4752
})
4853

4954
router.post('*', async (req, res) => {
50-
console.log('default path')
51-
return res.json({ message: "default path" })
55+
console.log('nothing to do path')
56+
return res.json({ message: "wrong method or path" })
5257
})
5358

5459
const uploadToAWS = async (config, excelData) => {
@@ -124,6 +129,7 @@ async function convertJsonToStyledExcel(jsonData, defaultStyle) {
124129
return buffer
125130
}
126131

132+
// const servicePrefix = process.env.SERVICE_PREFIX || '/'
127133
app.use('/', router)
128134

129135
const startServer = async () => {
@@ -139,8 +145,6 @@ if (!isAWSLambda) {
139145
const handler = serverless(app)
140146

141147
exports.handler = async (event, context, callback) => {
142-
// console.log("entryyyyyy---->", event)
143148
const response = await handler(event, context, callback)
144-
// console.log('request closed as response', response)
145149
return response
146150
}

0 commit comments

Comments
 (0)