Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

just reducing logging #3596

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/device-registry/utils/create-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -2531,9 +2531,8 @@ const createEvent = {
}

if (errors.length > 0 && isEmpty(eventsAdded)) {
console.log("API: failed to store measurements");
logger.error(
`🐛🐛 API: failed to store measurements ${stringify(errors)}`
console.log(
"API: failed to store measurements, most likely DB cast errors or duplicate records"
Comment on lines +2534 to +2535
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Improve logging consistency and error handling

The current implementation mixes console.log and logger.error for logging. Standardize on using the logger object for all logging to ensure consistency and better control over log levels.

Replace:

console.log("API: failed to store measurements, most likely DB cast errors or duplicate records");

and

console.log("API: successfully added the events");

with:

logger.error("API: failed to store measurements, most likely DB cast errors or duplicate records");

and

logger.info("API: successfully added the events");

Additionally, consider adding more granular error handling. Instead of catching all errors in a single try-catch block, handle specific error types separately. This will allow for more precise error messages and potentially different handling strategies for different types of errors.

Example:

try {
  // ... existing code
} catch (error) {
  if (error instanceof MongoError) {
    logger.error(`Database error: ${error.message}`);
    // Handle database-specific errors
  } else if (error instanceof ValidationError) {
    logger.error(`Validation error: ${error.message}`);
    // Handle validation errors
  } else {
    logger.error(`Unexpected error: ${error.message}`);
    // Handle other types of errors
  }
  next(new HttpError("Internal Server Error", httpStatus.INTERNAL_SERVER_ERROR, { message: error.message }));
}

This approach provides more detailed error logging and allows for more specific error handling strategies.

Also applies to: 2564-2571

);
return {
success: false,
Expand Down
Loading