Fantasy-Map-Generator/src/utils/errorUtils.ts
2022-06-26 19:20:31 +03:00

8 lines
434 B
TypeScript

// parse error to get the readable string
export function parseError(error: Error) {
const errorString = error.toString() + " " + error.stack;
const regex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gi;
const errorNoURL = errorString.replace(regex, url => "<i>" + url.split("/").at(-1) + "</i>");
const errorParsed = errorNoURL.replace(/at /gi, "<br>&nbsp;&nbsp;at ");
return errorParsed;
}