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

Get bookings via API returns 500 error #14735

Open
pgvr opened this issue Apr 24, 2024 · 3 comments
Open

Get bookings via API returns 500 error #14735

pgvr opened this issue Apr 24, 2024 · 3 comments
Labels
api area: API, enterprise API, access token, OAuth 🐛 bug Something isn't working

Comments

@pgvr
Copy link
Contributor

pgvr commented Apr 24, 2024

Found a bug? Please fill out the sections below. 👍

Issue Summary

Get bookings via API returns 500 error.
This happens for a certain API key, that I can share with someone from Cal.com, if need be.
For new keys that I create this request works.

Actual Results

  • Request returns 500 error

Expected Results

  • Request returns list of bookings

Evidence

image
Copy link

dosubot bot commented Apr 24, 2024

Hey there, @pgvr! 👋 Fancy seeing you here again - hope this message finds you less bugged than your API key seems to be. 😅 I'm diving into your issue as we speak, and I'll circle back with a diagnostic spell shortly. 🧙‍♂️

@dosubot dosubot bot added api area: API, enterprise API, access token, OAuth 🐛 bug Something isn't working labels Apr 24, 2024
@sumitdashrathgupta
Copy link

  1. Verify API Key: Ensure that the API key you're using for the requests causing the 500 error is correct and active. Check for any typos or discrepancies in the key.
  2. Check API Documentation: Review the documentation for the API endpoint you're trying to access. Make sure you're forming the request correctly, including any required headers or parameters.
  3. Review Error Logs: If possible, access error logs from the API server to see if there's more specific information about why the request is failing. This can provide insights into the root cause of the issue.
  4. Compare Requests: Compare the requests made with the working API keys to the one that's causing the error. Look for any differences in headers, parameters, or payload that could be contributing to the problem.
  5. Test in Isolation: If you have a sandbox or test environment for the API, try making the problematic request there. This can help determine if the issue is specific to the production environment or if it's related to the API key itself.
  6. Contact Support: If you're still unable to resolve the issue, reach out to the support team for the API provider. Provide them with details about the problem, including the specific endpoint, request payload, and any error messages received. If necessary, share the API key causing the problem with them for further investigation.
  7. Check for Rate Limits or Restrictions: Ensure that the API key causing the issue isn't subject to any rate limits or access restrictions that could be causing the 500 error. Review the API provider's documentation for any relevant information in this regard.

Copy link

dosubot bot commented Apr 24, 2024

To address the issue with the Get bookings via API returning a 500 error for a specific API key, consider the following steps:

  1. Enhance Error Handling: Ensure the handler function in apps/api/v1/pages/api/bookings/_get.ts is wrapped in a try-catch block to catch and handle exceptions, returning a JSON-formatted error message instead of an HTML response.

  2. Middleware and External Services: Verify that all middleware and external services are configured to return errors in JSON format, as the HTML error response suggests the issue might be outside the handler function.

  3. Server and Application Logs: Review server and application logs for errors or warnings related to the problematic API key to identify where the failure is happening.

  4. API Key Permissions: Double-check that the API key has the correct permissions and access rights to retrieve bookings.

  5. Rate Limiting: Confirm if the 500 error is due to the API key hitting its rate limit. Adjust your application to handle rate limits and provide meaningful responses if a limit is exceeded.

  6. Contact Support: If the issue persists, contact Cal.com support with detailed information, including the request being made and any relevant logs or error messages.

Here's an example modification for better error handling in the handler function:

async function handler(req: NextApiRequest) {
  try {
    // Your logic here...
    const data = await prisma.booking.findMany(args);
    return { bookings: data.map((booking) => schemaBookingReadPublic.parse(booking)) };
  } catch (error) {
    console.error("Error retrieving bookings:", error);
    if (error instanceof RateLimitError) {
      return res.status(429).json({ message: "Rate limit exceeded" });
    }
    throw new HttpError({ message: "An error occurred while retrieving bookings.", statusCode: 500 });
  }
}

This ensures exceptions are caught, and a JSON error response is returned, potentially resolving the issue with the HTML error response and improving the handling of rate limit errors.

Details

Sources


About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api area: API, enterprise API, access token, OAuth 🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants