Title: add more ruby like rescues method · Issue #77 · hyperstack-org/hyperstack · GitHub
Open Graph Title: add more ruby like rescues method · Issue #77 · hyperstack-org/hyperstack
X Title: add more ruby like rescues method · Issue #77 · hyperstack-org/hyperstack
Description: The after_error hook (called error boundaries in React) is quite primitive. But we can use it to build a more ruby like rescues hook: class MyComponent ... rescues do |error, info| ... # do whatever here end end Like ruby rescue, the res...
Open Graph Description: The after_error hook (called error boundaries in React) is quite primitive. But we can use it to build a more ruby like rescues hook: class MyComponent ... rescues do |error, info| ... # do whateve...
X Description: The after_error hook (called error boundaries in React) is quite primitive. But we can use it to build a more ruby like rescues hook: class MyComponent ... rescues do |error, info| ... # do whateve...
Opengraph URL: https://github.com/hyperstack-org/hyperstack/issues/77
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"add more ruby like rescues method","articleBody":"The `after_error` hook (called error boundaries in React) is quite primitive.\r\n\r\nBut we can use it to build a more ruby like `rescues` hook:\r\n\r\n```ruby\r\n\r\nclass MyComponent \r\n ...\r\n rescues do |error, info|\r\n ... # do whatever here\r\n end\r\nend\r\n```\r\n\r\nLike ruby `rescue`, the `rescues` method can take a list of exception classes. If the error raised is an instance of one of the exception classes, the rescues block will catch the error, otherwise it will get passed down the stack to any components further up (down?) the tree.\r\n\r\nLike ruby `rescue` you can have several `rescues` in a component each with different blocks, or you can share the block with multiple exception classes.\r\n\r\nLike ruby `rescue` if given no exception class `rescues` will default to `StandardError`\r\n\r\nAlso `rescues` will automatically create the necessary wrapper classes, so that you can rescue errors raised in the component you are defining. This is not possible with `after_error` which can only catch errors raised in components mounted from within the component defining the boundary.\r\n\r\n```ruby\r\nclass App \u003c HyperComponent\r\n include Hyperstack::Router\r\n\r\n SCOPES = %i[all active completed]\r\n VALID_ROUTES = \"/:scope(#{SCOPES.join('|')})\"\r\n\r\n class NoRouteMatched \u003c StandardError\r\n end\r\n\r\n render(SECTION, class: 'todo-app') do\r\n DIV { @flash_message }\r\n if @error_message\r\n DIV do\r\n DIV { @error_message }\r\n BUTTON { 'okay' }.on(:click) { mutate @error_message = nil }\r\n end\r\n else\r\n Header()\r\n Switch() do\r\n Route(App::VALID_ROUTES) { |match| Index(scope: Todo.send(match.params[:scope])) }\r\n Route('/', exact: true) { Redirect('/all') }\r\n Route('*') { |match| raise NoRouteMatched, match.url }\r\n end\r\n Footer()\r\n end\r\n end\r\n\r\n rescues NoRouteMatched do |err|\r\n mutate @flash_message = \"I did not recogonize #{err.message}\", history.push('/all')\r\n after(3) { mutate @flash_message = nil }\r\n end\r\n\r\n rescues do |err|\r\n mutate @error_message = \"Something went wrong! #{err}\"\r\n end\r\nend\r\n```","author":{"url":"https://github.com/catmando","@type":"Person","name":"catmando"},"datePublished":"2018-12-06T20:56:53.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/77/hyperstack/issues/77"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ccc3093b-ec94-cf16-3914-783ea75591fa |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8F78:5F0D6:1683555:1C7B1D4:69918262 |
| html-safe-nonce | f5afb9fc1409d741176c9716c337b909f7a2c588bdb8b394e816ba94ce7384bc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Rjc4OjVGMEQ2OjE2ODM1NTU6MUM3QjFENDo2OTkxODI2MiIsInZpc2l0b3JfaWQiOiIyMTUxNDk3OTYyNDI5MTg2NjU4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 34e2a27ba360772a9a0183955b32c534c0f5ded81fcc6e4da676c33a687d282e |
| hovercard-subject-tag | issue:388394388 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/hyperstack-org/hyperstack/77/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8911855296651b4ea74977c70a82ed72b0049791333ae3e2d4795314b8568d3f/hyperstack-org/hyperstack/issues/77 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8911855296651b4ea74977c70a82ed72b0049791333ae3e2d4795314b8568d3f/hyperstack-org/hyperstack/issues/77 |
| og:image:alt | The after_error hook (called error boundaries in React) is quite primitive. But we can use it to build a more ruby like rescues hook: class MyComponent ... rescues do |error, info| ... # do whateve... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | catmando |
| hostname | github.com |
| expected-hostname | github.com |
| None | 42c603b9d642c4a9065a51770f75e5e27132fef0e858607f5c9cb7e422831a7b |
| turbo-cache-control | no-preview |
| go-import | github.com/hyperstack-org/hyperstack git https://github.com/hyperstack-org/hyperstack.git |
| octolytics-dimension-user_id | 34562730 |
| octolytics-dimension-user_login | hyperstack-org |
| octolytics-dimension-repository_id | 145879576 |
| octolytics-dimension-repository_nwo | hyperstack-org/hyperstack |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 145879576 |
| octolytics-dimension-repository_network_root_nwo | hyperstack-org/hyperstack |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 848bc6032dcc93a9a7301dcc3f379a72ba13b96e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width