import{r as n,j as t}from"./vendor-react-wBh_31cN.js";import{G as p,J as v,aq as b,$ as k,r as C,R as y}from"./index-BKr2rJhV.js";import{u as $}from"./useNotifier-BCEAoFCf.js";import{j,u as l}from"./vendor-redux-CJZrIb6x.js";import{V as m}from"./value-76ihWpF6.js";import{A as D}from"./avatar-U0jpGcgI.js";import{E as O}from"./Error-ehOSFm_s.js";import{c as R,u as T}from"./vendor-router-D1GqFWiT.js";import{E as d}from"./Error404-B4n3go6x.js";const G=()=>{const e=n.useCallback(()=>window.location.reload(),[]);return t.jsxs("div",{className:"flex flex-col items-center my-auto",children:[t.jsx(m,{className:"text-[22px] mb-3",children:"Connection Error"}),t.jsx(m,{className:"mb-10",children:"Cannot reach the server"}),t.jsx("div",{className:"flex",children:t.jsx(p,{variant:"secondary",onClick:e,className:"mr-3.5",children:"Reload"})})]})},P=n.memo(G),S=()=>{const{id:e}=R(),s=j(),r=l(i=>i.crossProject),{data:{firstname:c}={}}=v();return n.useEffect(()=>{s.crossProject.getCrossUserProject(+e)},[s,e]),!c||!(r!=null&&r.owner)?t.jsx(b,{}):t.jsx(O,{errorTitle:"403",errorMessage:`Sorry ${c}, you are not invited.`,children:t.jsxs("div",{className:"flex flex-col items-center",children:[t.jsx(D,{firstName:r.owner.fname,lastName:r.owner.lname,size:"lg"}),t.jsx("span",{className:"mt-1 text-xs text-muted-foreground",children:r.owner.email}),t.jsx(m,{className:"mt-2",children:`You are not a member of ${r.name},        created by ${r.owner.fname} ${r.owner.lname}`})]})})},U=n.memo(S),A=401,I=403,q=404,N=e=>e>=400&&e<500,w=e=>e>=500,u=e=>{var s;return((s=e==null?void 0:e.response)==null?void 0:s.status)??(e==null?void 0:e.status)},F=e=>{var s;return((s=e==null?void 0:e.response)==null?void 0:s.data)??(e==null?void 0:e.data)},M=e=>typeof e=="string"?e||void 0:(e==null?void 0:e.usrMsg)??(e==null?void 0:e.errorMsg),g=e=>{if(e.message==="Network Error")return"Network issue";const s=u(e);return s&&w(s)?"Server Error":s&&N(s)?"Client Error":"Error"},h=e=>{if(e.message==="Network Error")return t.jsxs("span",{className:"flex items-center",children:[t.jsx(y,{children:"Try again or"}),t.jsx(p,{variant:"link",className:"-ml-2.5",onClick:()=>window.open("https://community.hopsworks.ai","_blank"),children:"contact the support"})]});const s=u(e),r=M(F(e));return s&&w(s)?r&&r!=="A generic error occurred."?r:"This page can not reach the server":s&&N(s)?r??"Error occurred.":"Error occurred."},z=({children:e})=>{var E,x;const{isServiceUser:s}=k(),r=l(a=>a.error.globalError),c=j(),i=T(),f=$(),o=l(a=>a.error.error);if(n.useEffect(()=>{o&&u(o)!==A&&(f.error({title:g(o),content:h(o),uniqueId:"unauthorized-error"}),c.error.clearError())},[o]),n.useEffect(()=>{var a;r&&((a=r.config)==null?void 0:a.method)!=="get"&&f.error({title:g(r),content:h(r),uniqueId:"global-error"})},[r]),n.useEffect(()=>{(o==null?void 0:o.message)==="Network Error"&&i(C.home)},[o]),r&&((E=r.config)==null?void 0:E.method)==="get")switch(r.status||((x=r.response)==null?void 0:x.status)){case q:return t.jsx(d,{});case I:return s?t.jsx(d,{}):t.jsx(U,{});default:return t.jsx(P,{})}return e},K=n.memo(z);export{K as G,h as a,g};
