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

improve fetching agendabasel data #189

Merged
merged 4 commits into from
Oct 16, 2024

Conversation

koilebeit
Copy link
Contributor

@koilebeit koilebeit commented Sep 30, 2024

Pull request

Proposed changes

solves #186

Types of changes

  • New feature (non-breaking change which adds functionality).
  • Enhancement (non-breaking change which enhances functionality)
  • Bug Fix (non-breaking change which fixes an issue).
  • Breaking change (fix or feature that would cause existing functionality to change).

Checklist

  • I have read the README document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling and response validation for activity fetching, ensuring better feedback on failures.
    • Enhanced logging for development mode to aid in troubleshooting.
    • Added validation to check for outdated export files, improving data accuracy.
  • Chores

    • Updated error handling mechanisms to differentiate between development and production environments.
    • Wrapped XML parsing in a try-catch block for better error management.

Copy link

changeset-bot bot commented Sep 30, 2024

⚠️ No Changeset found

Latest commit: ff05611

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Sep 30, 2024

Walkthrough

The changes made to the src/routes/agenda.json/+server.js file focus on enhancing the error handling and response validation within the getActivities function. The implementation now verifies the success of HTTP responses and checks for non-empty response bodies. Additionally, XML parsing is safeguarded with try-catch blocks to manage potential errors, and the function checks the freshness of the export file by validating the ExportFileLastUpdate date. The overall data processing structure remains unchanged.

Changes

Files Change Summary
src/routes/agenda.json/+server.js Enhanced error handling and response validation in getActivities function; checks for successful responses and non-empty bodies; added XML parsing error handling and validation of ExportFileLastUpdate date.

Possibly related PRs

  • update agendabasel url #185: This PR modifies the getActivities function in the same file, specifically changing the URL used in the fetch call, which is directly related to the data retrieval process that the main PR enhances with improved error handling and validation logic.

Suggested reviewers

  • maehr

Poem

In the land of code where rabbits play,
Errors once lurked, but now they sway.
With checks in place, the path is clear,
Fetching activities brings us cheer!
In dev we log, in prod we halt,
A robust dance, no need to fault! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ceb2e73 and ff05611.

📒 Files selected for processing (1)
  • src/routes/agenda.json/+server.js (1 hunks)
🧰 Additional context used
🔇 Additional comments (7)
src/routes/agenda.json/+server.js (7)

81-83: Good inclusion of HTTP status code in error message

Including both response.status and response.statusText in the error message enhances debugging capabilities by providing detailed information about the HTTP failure.


89-91: Proper handling of empty responses

Checking for an empty response ensures that the application handles cases where the server returns no data, preventing potential parsing errors.


94-98: Robust XML parsing with error handling

Wrapping the XML parsing in a try-catch block and providing a clear error message improves resilience against malformed or invalid XML data.


115-118: Development-only logging and data saving

Conditionally executing saveToFile and console.log when dev is true ensures that sensitive data is not exposed in production environments.


136-137: Duplicate Comment: Consider allowing safe HTML tags in descriptions

As previously noted, stripping all HTML tags removes useful formatting from descriptions. Consider using DOMPurify without specifying ALLOWED_TAGS to preserve safe HTML content.


140-146: Duplicate Comment: Safely access TicketURL when it may be missing

The destructuring assumes TicketURL always exists, which could lead to errors if it's undefined. Providing a default value ensures safe access when TicketURL is missing.


162-168: Appropriate error handling for different environments

Rethrowing the original error in development mode aids in debugging, while wrapping the error with a user-friendly message in production maintains a smooth user experience.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🧹 Outside diff range and nitpick comments (1)
src/routes/agenda.json/+server.js (1)

132-135: Ensure consistent sorting of exhibitions and events

The exhibitions are sorted by the owner's name, but events are not sorted. For a consistent user experience, consider sorting events as well.

Apply this diff to sort events by start date and owner:

    const events = parsedActivities.filter(({ dauerausstellung }) => dauerausstellung === '0');

    const flatEvents = events
        .flatMap(({ dates, owner, title, shortDescription, originUrl }) =>
            dates.map((date) => ({ ...date, owner, title, shortDescription, originUrl }))
        )
-       .sort((a, b) => new Date(a.startDate).getTime() - new Date(b.startDate).getTime());
+       .sort((a, b) => {
+           const dateComparison = new Date(a.startDate) - new Date(b.startDate);
+           return dateComparison !== 0 ? dateComparison : a.owner.localeCompare(b.owner);
+       });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 740ebc3 and a9d9270.

📒 Files selected for processing (1)
  • src/routes/agenda.json/+server.js (1 hunks)

src/routes/agenda.json/+server.js Outdated Show resolved Hide resolved
src/routes/agenda.json/+server.js Outdated Show resolved Hide resolved
src/routes/agenda.json/+server.js Show resolved Hide resolved
src/routes/agenda.json/+server.js Outdated Show resolved Hide resolved
src/routes/agenda.json/+server.js Show resolved Hide resolved
src/routes/agenda.json/+server.js Show resolved Hide resolved
@koilebeit koilebeit requested a review from maehr October 1, 2024 08:03
Copy link
Member

@maehr maehr left a comment

Choose a reason for hiding this comment

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

@koilebeit Thanks for the PR. It covers most of the cases of agendabasel api breakdowns. However, one case is missing: outdated data (not updating on their end). Can you check for entries added in the last two weeks as well?

@koilebeit koilebeit requested a review from maehr October 16, 2024 09:42
@maehr maehr merged commit aac43be into Stadt-Geschichte-Basel:main Oct 16, 2024
4 checks passed
@koilebeit koilebeit deleted the agendabasel_api branch October 17, 2024 06:23
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.

2 participants