1
0
mirror of https://github.com/sasjs/server.git synced 2026-01-09 23:40:06 +00:00

fix(api-cdrive-oller): throw erow error when file not found

This commit is contained in:
2021-10-25 05:51:46 +00:00
parent 70a8aaf600
commit 03d1d60660
4 changed files with 45 additions and 21 deletions

View File

@@ -3,7 +3,7 @@ import path from 'path'
import {
createFileTree,
getTreeExample,
SASjsDriveController,
DriveController,
ExecutionController,
FileUploadController
} from '../controllers'
@@ -55,8 +55,18 @@ router.get('/SASjsApi/files', async (req, res) => {
const filePath = path
.join(getTmpFilesFolderPath(), req.query.filePath)
.replace(new RegExp('/', 'g'), path.sep)
const fileContent = await new SASjsDriveController().readFile(filePath)
res.status(200).send({ status: 'success', fileContent: fileContent })
await new DriveController()
.readFile(filePath)
.then((fileContent) => {
res.status(200).send({ status: 'success', fileContent: fileContent })
})
.catch((err) => {
res.status(400).send({
status: 'failure',
message: 'File request failed.',
...(typeof err === 'object' ? err : { details: err })
})
})
} else {
res.status(400).send({
status: 'failure',
@@ -69,8 +79,18 @@ router.post('/SASjsApi/files', async (req, res) => {
const filePath = path
.join(getTmpFilesFolderPath(), req.body.filePath)
.replace(new RegExp('/', 'g'), path.sep)
await new SASjsDriveController().updateFile(filePath, req.body.fileContent)
res.status(200).send({ status: 'success' })
await new DriveController()
.updateFile(filePath, req.body.fileContent)
.then(() => {
res.status(200).send({ status: 'success' })
})
.catch((err) => {
res.status(400).send({
status: 'failure',
message: 'File request failed.',
...(typeof err === 'object' ? err : { details: err })
})
})
})
router.get('/SASjsApi/executor', async (req, res) => {