정민우

[Edit] dockerfile add 예외처리

......@@ -19,21 +19,27 @@ exports.addDockerfile = async (req, res) => {
logging('dockerfile', 'error', { code: 400, message: `missingKey:${required}` }, req)
return sendError(res, 400, `missingKey:${required}`)
}
let dockerfileInfo = {}
dockerfileInfo.userId = id
dockerfileInfo.content = req.body.content
let dockerfileDir = randomstring.generate(16);
fs.mkdirSync('./dockerfiles/'+dockerfileDir)
dockerfileInfo.filepath = './dockerfiles/'+dockerfileDir+'/Dockerfile'
fs.writeFile(dockerfileInfo.filepath, dockerfileInfo.content, function (err) {
if (err) {
logging('dockerfile', 'error', { code: 400, message: `dockerfile write error` }, req)
return sendError(res, 400, `dockerfile write error`)
}
})
let user = await Dockerfile.create(dockerfileInfo)
logging('dockerfile', 'add dockerfile', user, req)
return sendResponse(res, user, 200)
try {
let dockerfileInfo = {}
dockerfileInfo.userId = id
dockerfileInfo.content = req.body.content
let dockerfileDir = randomstring.generate(16);
fs.mkdirSync('./dockerfiles/'+dockerfileDir)
dockerfileInfo.filepath = './dockerfiles/'+dockerfileDir+'/Dockerfile'
fs.writeFile(dockerfileInfo.filepath, dockerfileInfo.content, function (err) {
if (err) {
logging('dockerfile', 'error', { code: 400, message: `dockerfile write error` }, req)
return sendError(res, 400, `dockerfile write error`)
}
})
let user = await Dockerfile.create(dockerfileInfo)
logging('dockerfile', 'add dockerfile', user, req)
return sendResponse(res, user, 200)
} catch (error) {
logging('dockerfile', 'error', { code: 500, message: error.message }, req)
return sendError(res, 500, error.message)
}
}
exports.listDockerfile = async (req, res) => {
......