mirror of
https://github.com/coleam00/bolt.new-any-llm
synced 2024-12-27 22:33:03 +00:00
7eee0386ff
Some checks are pending
Update Stable Branch / prepare-release (push) Waiting to run
* Catch errors from web container * Show fix error popup on errors in preview * Remove unneeded action type * PR comments * Cleanup urls in stacktrace --------- Co-authored-by: Anirban Kar <thecodacus@gmail.com>
28 lines
827 B
TypeScript
28 lines
827 B
TypeScript
/**
|
|
* Cleans webcontainer URLs from stack traces to show relative paths instead
|
|
*/
|
|
export function cleanStackTrace(stackTrace: string): string {
|
|
// Function to clean a single URL
|
|
const cleanUrl = (url: string): string => {
|
|
const regex = /^https?:\/\/[^\/]+\.webcontainer-api\.io(\/.*)?$/;
|
|
|
|
if (!regex.test(url)) {
|
|
return url;
|
|
}
|
|
|
|
const pathRegex = /^https?:\/\/[^\/]+\.webcontainer-api\.io\/(.*?)$/;
|
|
const match = url.match(pathRegex);
|
|
|
|
return match?.[1] || '';
|
|
};
|
|
|
|
// Split the stack trace into lines and process each line
|
|
return stackTrace
|
|
.split('\n')
|
|
.map((line) => {
|
|
// Match any URL in the line that contains webcontainer-api.io
|
|
return line.replace(/(https?:\/\/[^\/]+\.webcontainer-api\.io\/[^\s\)]+)/g, (match) => cleanUrl(match));
|
|
})
|
|
.join('\n');
|
|
}
|