<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="212091" data-post-id="212091">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="benwilson512" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/benwilson512/120/1457_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  benwilson512
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Author of Craft GraphQL APIs in Elixir with Absinthe</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><code>def</code> already supports the following form:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def handle_event("event", args, socket) do
  # whatever
rescue
 e -&gt;
  # handle exception here
end
</code></pre>
<p>This lets you skip the boilerplate of an additional <code>try do end</code></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="212091" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-notify-a-user-about-exception-in-liveview-handle-event/39127/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-212091" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="212091"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="212097" data-post-id="212097">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="derek-zhou" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/derek-zhou/120/19943_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  derek-zhou
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>But if I have many handle_event/3 clauses, I still need to duplicate the <code>rescue</code> part. <a class="mention" href="/u/athunnea" rel="nofollow">@Athunnea</a> just needs a standard way to redirect to a known 500 page if anything bad happen.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="212097" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-notify-a-user-about-exception-in-liveview-handle-event/39127/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-212097" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="212097"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="212311" data-post-id="212311">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="evadne" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/evadne/120/13949_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  evadne
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>assuming your LV does crash then on JavaScript side doing this</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">liveSocket.channel.onError(thing)
</code></pre>
<p>should get you a trigger that works</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="212311" data-batch-url="/posts/batch_likers">
                        3
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-notify-a-user-about-exception-in-liveview-handle-event/39127/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-212311" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="212311"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="212353" data-post-id="212353">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="soup" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/soup/120/31425_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  soup
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><code>Uncaught TypeError: liveSocket.channel.onError is not a function</code></p>
<p>I don’t think live socket exposes the same interface as the <a href="https://hexdocs.pm/phoenix/js/#channelonerror" rel="noopener nofollow ugc">normal socket</a>.</p>
<p>AFAIK, each view has it’s own channel (?),  you might be able to hook into each views create/mount call back and use that to <a href="https://github.com/phoenixframework/phoenix_live_view/blob/188d5d749c9bdc7b7ae9198d58e2dac6b6263c2a/assets/js/phoenix_live_view.js#L815-L825" rel="noopener nofollow ugc">bind an “error” handler with the view name (aka channel name?)</a>, but I believe the “event” passed around here is more like “phx_update”, not a socket error. I didn’t read too hard or actually test it.</p>
<p>Edit: <code>this.viewName</code> is more like <code>MyApp.View</code>, you need <code>this.__view</code> which is definitely getting weedsy and unsupported, <code>onChannel</code> is marked private too so not recommended to build on.</p>
<p>I think it would be a good feature to have, an easy way to bind per-view error handlers. Maybe another client hook lifecycle callback or a param to destroyed indicating if it was a clean exit or not.</p>
<p>That would probably need the core LV to be patched with the rescue block I guess.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="212353" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-notify-a-user-about-exception-in-liveview-handle-event/39127/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-212353" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="212353"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>