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

fix: health endpoint s3 connection #2136

Merged
merged 1 commit into from
Feb 27, 2024
Merged

fix: health endpoint s3 connection #2136

merged 1 commit into from
Feb 27, 2024

Conversation

mattinannt
Copy link
Member

What does this PR do?

fix: health endpoint s3 connection

Copy link

vercel bot commented Feb 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
formbricks-cloud ⬜️ Ignored (Inspect) Feb 27, 2024 0:19am
formbricks-com ⬜️ Ignored (Inspect) Feb 27, 2024 0:19am

Copy link
Contributor

Thank you for following the naming conventions for pull request titles! 🙏

Copy link
Contributor

Here are some suggestions to improve the code:

  1. In page.tsx, when catching the error in checkS3Connection, it would be better to include the original error message in the thrown error to provide more context about what went wrong. This can be done by appending e.message to the thrown error message.
try {
  await testS3BucketAccess();
} catch (e) {
-  throw new Error("S3 Bucket cannot be accessed");
+  throw new Error(`S3 Bucket cannot be accessed: ${e.message}`);
}
  1. In service.ts, it's good that you're logging the error when the S3 bucket access test fails. However, it would be better to use a more specific error message when throwing the error. This can be done by using the error.code property, which provides a more specific error message.
catch (error) {
-  console.error("Failed to access S3 bucket:", error);
-  throw new Error(`S3 Bucket Access Test Failed: ${error}`);
+  console.error(`Failed to access S3 bucket: ${error.code}`);
+  throw new Error(`S3 Bucket Access Test Failed: ${error.code}`);
}
  1. In service.ts, it's not necessary to return true in testS3BucketAccess function. If the function doesn't throw an error, it means that the bucket access test passed. So, you can remove the return true; line.
try {
  // Attempt to retrieve metadata about the bucket
  const headBucketCommand = new HeadBucketCommand({
    Bucket: S3_BUCKET_NAME,
  });

  await s3Client.send(headBucketCommand);

-  return true;
} catch (error) {
  console.error("Failed to access S3 bucket:", error);
  throw new Error(`S3 Bucket Access Test Failed: ${error}`);
}

@mattinannt mattinannt merged commit 32dcb75 into main Feb 27, 2024
14 checks passed
@mattinannt mattinannt deleted the fix/health-ep branch February 27, 2024 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant