Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/orange-penguins-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/dashboard": patch
---

Chore/send admin error to parent
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ExclamationCircle } from "@medusajs/icons"
import { Text } from "@medusajs/ui"
import { useEffect } from "react"
import { useTranslation } from "react-i18next"
import { Navigate, useLocation, useRouteError } from "react-router-dom"

Expand All @@ -12,6 +13,41 @@ export const ErrorBoundary = () => {

let code: number | null = null

/**
* Send error to parent frame when running in an iframe, e.g. for Bloom sandboxes.
*/
useEffect(() => {
if (window !== window.parent && error) {
let filename: string | undefined
let lineno: number | undefined
let colno: number | undefined

if (error instanceof Error && error.stack) {
// Parse the first location from the stack trace
const match = error.stack.match(
/at\s+(?:\S+\s+\()?(https?:\/\/[^)]+):(\d+):(\d+)/
)
if (match) {
filename = match[1]
lineno = parseInt(match[2], 10)
colno = parseInt(match[3], 10)
}
}

const errorPayload = {
type: "ADMIN_RUNTIME_ERROR",
error: {
message: error instanceof Error ? error.message : String(error),
filename,
lineno,
colno,
stack: error instanceof Error ? error.stack : undefined,
},
}
window.parent.postMessage(errorPayload, "*")
}
}, [error])

if (isFetchError(error)) {
if (error.status === 401) {
return <Navigate to="/login" state={{ from: location }} replace />
Expand Down