Skip to content

Commit

Permalink
storage-service: optimize log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
laurenzhonauer committed Oct 27, 2021
1 parent 11a98b0 commit e1aa3a6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions storage-service/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ app.use(
var msg =
"The CORS policy for this site does not " +
"allow access from the specified Origin.";
log.debug(msg);
return callback(new Error(msg), false);
}
return callback(null, true);
Expand Down Expand Up @@ -97,13 +98,15 @@ app.post(
(req: DocumentUploadRequest, res: express.Response) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
log.error({ err: errors }, "Error while validating request");
return res.status(400).json({ errors: errors.array() }).end();
}

const docId: string = req.query.docId;
const { content, fileName } = req.body;

(async () => {
log.debug({ req }, "Uploading document");
const result = await uploadAsPromised(docId, content, {
fileName,
docId,
Expand All @@ -112,7 +115,7 @@ app.post(
})().catch((err) => {
if (err.code === "NoSuchBucket") {
req.log.error(
err,
{ err },
"NoSuchBucket at /upload. Please restart storage-service to create a new bucket at minio",
);
}
Expand All @@ -127,6 +130,7 @@ app.get(
(req: DocumentDownloadRequest, res: express.Response) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
req.log.error({err: errors}, "Error while validating request");
return res.status(404).end();
}
const docId: string = req.query.docId;
Expand All @@ -139,6 +143,7 @@ app.get(

// first get document
(async () => {
req.log.debug({req}, "Downloading document");
const result = await downloadAsPromised(docId);

//check if the given secret matches the one form the metadata
Expand All @@ -150,7 +155,7 @@ app.get(
})().catch((err) => {
if (err.code === "NoSuchBucket") {
req.log.error(
err,
{err},
"NoSuchBucket at /download. Please restart storage-service to create a new bucket at minio",
);
}
Expand Down
3 changes: 2 additions & 1 deletion storage-service/src/minio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const download = (file: string, cb: Function) => {
log.error({ err }, "Error during getting file object");
cb(err);
} else {
log.trace("Fetching data from stream");
dataStream.on("data", (chunk: string) => {
fileContent += chunk;
});
Expand Down Expand Up @@ -196,7 +197,7 @@ export const establishConnection = async () => {
break;
} catch (err) {
log.error(
err,
{ err },
"Problem with establishing connection to min.io and creating bucket.",
);

Expand Down

0 comments on commit e1aa3a6

Please sign in to comment.