Showing
1 changed file
with
21 additions
and
15 deletions
... | @@ -19,21 +19,27 @@ exports.addDockerfile = async (req, res) => { | ... | @@ -19,21 +19,27 @@ exports.addDockerfile = async (req, res) => { |
19 | logging('dockerfile', 'error', { code: 400, message: `missingKey:${required}` }, req) | 19 | logging('dockerfile', 'error', { code: 400, message: `missingKey:${required}` }, req) |
20 | return sendError(res, 400, `missingKey:${required}`) | 20 | return sendError(res, 400, `missingKey:${required}`) |
21 | } | 21 | } |
22 | - let dockerfileInfo = {} | 22 | + try { |
23 | - dockerfileInfo.userId = id | 23 | + let dockerfileInfo = {} |
24 | - dockerfileInfo.content = req.body.content | 24 | + dockerfileInfo.userId = id |
25 | - let dockerfileDir = randomstring.generate(16); | 25 | + dockerfileInfo.content = req.body.content |
26 | - fs.mkdirSync('./dockerfiles/'+dockerfileDir) | 26 | + let dockerfileDir = randomstring.generate(16); |
27 | - dockerfileInfo.filepath = './dockerfiles/'+dockerfileDir+'/Dockerfile' | 27 | + fs.mkdirSync('./dockerfiles/'+dockerfileDir) |
28 | - fs.writeFile(dockerfileInfo.filepath, dockerfileInfo.content, function (err) { | 28 | + dockerfileInfo.filepath = './dockerfiles/'+dockerfileDir+'/Dockerfile' |
29 | - if (err) { | 29 | + fs.writeFile(dockerfileInfo.filepath, dockerfileInfo.content, function (err) { |
30 | - logging('dockerfile', 'error', { code: 400, message: `dockerfile write error` }, req) | 30 | + if (err) { |
31 | - return sendError(res, 400, `dockerfile write error`) | 31 | + logging('dockerfile', 'error', { code: 400, message: `dockerfile write error` }, req) |
32 | - } | 32 | + return sendError(res, 400, `dockerfile write error`) |
33 | - }) | 33 | + } |
34 | - let user = await Dockerfile.create(dockerfileInfo) | 34 | + }) |
35 | - logging('dockerfile', 'add dockerfile', user, req) | 35 | + let user = await Dockerfile.create(dockerfileInfo) |
36 | - return sendResponse(res, user, 200) | 36 | + logging('dockerfile', 'add dockerfile', user, req) |
37 | + return sendResponse(res, user, 200) | ||
38 | + } catch (error) { | ||
39 | + logging('dockerfile', 'error', { code: 500, message: error.message }, req) | ||
40 | + return sendError(res, 500, error.message) | ||
41 | + } | ||
42 | + | ||
37 | } | 43 | } |
38 | 44 | ||
39 | exports.listDockerfile = async (req, res) => { | 45 | exports.listDockerfile = async (req, res) => { | ... | ... |
-
Please register or login to post a comment