admin管理员组文章数量:1400148
I have a React web app in which I am embedding Tableau reports. I am also using JWT token for security. When a user is not authorize to view a report I want to show an error message on the page however there is no way I am able to find to listen to the error.
import React, { useEffect, useRef } from "react";
const TableauViz = ({ src, options, token }) => {
const vizContainer = useRef(null);
useEffect(() => {
// Initialize the Tableau Viz web component
const vizElement = document.createElement("tableau-viz");
vizElement.id = "tableauViz";
vizElement.src = src;
vizElement.token = token;
// Add options as attributes
for (const [key, value] of Object.entries(options)) {
vizElement.setAttribute(key, value);
}
// Append the viz element to the container
vizContainer.current.innerHTML = "";
vizContainer.current.appendChild(vizElement);
}, [src, options]);
return <div ref={vizContainer} className="tableau-viz-container m-auto" />;
};
export default TableauViz;
Above is my code. Users are able to view the reports if they are authorized. Also this code internally fires a network request for checking the authorization but that is not in my control so when it throws 401 or some other error then I am unable to catch and display it.
As per the docs, I did try listening to the onVizLoadError event but that didn't work. Tableau documentation for listening to error
function handleError(ev){
console.log("handleError", ev);
}
useEffect(() => {
// Initialize the Tableau Viz web component
const vizElement = document.createElement("tableau-viz");
vizElement.id = "tableauViz";
vizElement.src = src;
vizElement.token = token;
vizElement.onVizLoadError = handleError;
// Add options as attributes
for (const [key, value] of Object.entries(options)) {
vizElement.setAttribute(key, value);
}
// Append the viz element to the container
vizContainer.current.innerHTML = "";
vizContainer.current.appendChild(vizElement);
}, [src, options]);
I tried listening to onVizLoader like this, even tried to it view addeventlistener but they did not work, nothing printed in the console.
Any help will be appreciated.
本文标签: javascriptHow to catch 401 or other errors in Tableau embed ReactJsStack Overflow
版权声明:本文标题:javascript - How to catch 401 or other errors in Tableau embed ReactJs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744251709a2597282.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论