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

feat: Add errorCallback config option to VivliostylePrint/printHTML() #1287

Merged
merged 1 commit into from
Feb 23, 2024

Conversation

MurakamiShinyu
Copy link
Member

@MurakamiShinyu MurakamiShinyu commented Feb 22, 2024

So far VivliostylePrint has no way to handle errors. This PR adds a new config option errorCallback to VivliostylePrint/printHTML() to handle errors.

Usage example:

  const config = {
    errorCallback: (message) => {
      alert(message);
    }
  };
  printHTML(htmlDoc, config);

This PR also fixes the following issues on error handling:

  • Payload.content type should be ErrorInfo instead of string.
  • loadDocument() and loadPublication() in CoreViewer needed to fix the "No URL specified" error handling.
  • Logging.logger.addListener(level, listener) used to push a listener to an array per level so that multiple listeners can be registered for the same level. However, that was problematic because the Logging.logger is a singleton instance but the CoreViewer instance with an AdaptiveViewer instance is created each time printHTML() is called, and new listeners are added each time without removing the old ones, causing the listeners to be duplicated. This commit changes the Logging.logger.addListener method to replace the listener for the level if it already exists.

#1268

Copy link

vercel bot commented Feb 22, 2024

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

Name Status Preview Comments Updated (UTC)
vivliostyle ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 23, 2024 6:45am

@MurakamiShinyu MurakamiShinyu marked this pull request as draft February 22, 2024 16:51
So far VivliostylePrint has no way to handle errors. This commit adds a new config option `errorCallback` to VivliostylePrint/`printHTML()` to handle errors.

Usage example:

```ts
  const config = {
    errorCallback: (message) => {
      alert(message);
    }
  };
  printHTML(htmlDoc, config);
```

This commit also fixes the following issues on error handling:

- `Payload.content` type should be `ErrorInfo` instead of `string`.
- `loadDocument()` and `loadPublication()` in CoreViewer needed to fix the "No URL specified" error handling.
- `Logging.logger.addListener(level, listener)` used to push a listener to an array per level so that multiple listeners can be registered for the same level. However, that was problematic because the `Logging.logger` is a singleton instance but the CoreViewer instance with an AdaptiveViewer instance is created each time `printHTML()` is called, and new listeners are added each time without removing the old ones, causing the listeners to be duplicated. This commit changes the `addListener` method to replace the listener for the level if it already exists.
@MurakamiShinyu
Copy link
Member Author

Also made a pull request for vivliostyle-print to use this errorCallback in demo:

@MurakamiShinyu MurakamiShinyu merged commit ebcc38a into master Feb 23, 2024
5 checks passed
@MurakamiShinyu MurakamiShinyu deleted the feat/vivliostyle-print-error branch February 23, 2024 08:27
@MurakamiShinyu
Copy link
Member Author

NOTE: This PR solves a problem noted in #1268.

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