Skip to content

Commit

Permalink
make log messages uniform
Browse files Browse the repository at this point in the history
  • Loading branch information
PipeItToDevNull committed Dec 7, 2024
1 parent 6712562 commit ad686ae
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const analyzeFile = (filePath, res) => {
});

if (error) {
logger.error(`Error analyzing target: ${error.message}`);
logger.error(`Failed to analyze target: ${error.message}`);
res.status(500).send(`An error occurred while analyzing the file`);
return;
}
Expand All @@ -118,7 +118,7 @@ const analyzeFile = (filePath, res) => {
res.json(jsonOutput);
} catch (parseError) {
logger.error(`Failed to parse JSON output: ${parseError.message}`);
res.status(500).send({ error: 'Failed to parse JSON output' });
res.status(500).send('An error occured while parsing JSON output');
}
});
};
Expand Down Expand Up @@ -151,15 +151,15 @@ const handleAnalyzeDmp = async (req, res) => {
resolve();
});
writer.on('error', (err) => {
logger.error(`Error downloading file: ${err.message}`);
res.status(500).send(`Error downloading file: ${err.message}`);
logger.error(`Failed to download file: ${err.message}`);
res.status(500).send(`An error occured while downloading file: ${err.message}`);
reject(err);
});
});

} catch (error) {
logger.error(`Error fetching URL: ${error.message}`);
res.status(500).send(`Error fetching URL: ${error.message}`);
logger.error(`Failed to fetch URL: ${error.message}`);
res.status(500).send(`An error occured while fetching URL: ${error.message}`);
return; // Terminate on invalid URL
}
} else {
Expand All @@ -185,8 +185,8 @@ const handleAnalyzeDmp = async (req, res) => {
analyzeFile(filePath, res); // Analyze the extracted directory
})
.on('error', (err) => {
logger.error(`Error extracting .zip file: ${err.message}`);
res.status(500).send(`Error extracting .zip file: ${err.message}`);
logger.error(`Failed to extract .zip file: ${err.message}`);
res.status(500).send(`An error occured while extracting .zip file: ${err.message}`);
});
} else {
logger.warn('Unsupported file type');
Expand All @@ -203,8 +203,8 @@ const handleAnalyzeDmp = async (req, res) => {
const filePath = `${uploadPath}.dmp`;
fs.rename(uploadPath, filePath, (err) => {
if (err) {
logger.error('Error renaming file:', err);
res.status(500).send(`Error renaming file: ${error.message}`);
logger.error('Failed to rename file:', err);
res.status(500).send(`An error occured while renaming file: ${error.message}`);
} else {
logger.info(`Renamed file: ${filePath}`);
}
Expand All @@ -227,8 +227,8 @@ app.get('/', (req, res) => {
const readmePath = path.join(__dirname, 'USAGE.md');
fs.readFile(readmePath, 'utf8', (err, data) => {
if (err) {
logger.error(`Error reading README file: ${err.message}`);
res.status(500).send(`Error reading README file: ${err.message}`);
logger.error(`Failed to read README file: ${err.message}`);
res.status(500).send(`An error occured while reading README file: ${err.message}`);
return;
}
const htmlContent = marked(data, { mangle: false, headerIds: false });
Expand All @@ -238,7 +238,7 @@ app.get('/', (req, res) => {

// Centralized error handling middleware
app.use((err, req, res, next) => {
logger.error(`Unhandled error: ${err.stack}`);
logger.error(`Unhandled failure: ${err.stack}`);
res.status(500).send('Something broke, I lost my 418');
});

Expand Down

0 comments on commit ad686ae

Please sign in to comment.