Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
@@ -0,0 +1,40 @@
|
||||
const SAFE_ERROR_NAMES = new Set([
|
||||
"AbortError",
|
||||
"AggregateError",
|
||||
"CatalogError",
|
||||
"Error",
|
||||
"PrismaClientInitializationError",
|
||||
"PrismaClientKnownRequestError",
|
||||
"PrismaClientUnknownRequestError",
|
||||
"PrismaClientValidationError",
|
||||
"RangeError",
|
||||
"ReferenceError",
|
||||
"SyntaxError",
|
||||
"TenantSlugCollisionError",
|
||||
"TimeoutError",
|
||||
"TypeError",
|
||||
"URIError",
|
||||
]);
|
||||
const SAFE_NODE_ERROR_CODES = new Set(["ABORT_ERR", "EAI_AGAIN", "ECONNREFUSED", "ECONNRESET", "ENETUNREACH", "ENOTFOUND", "ETIMEDOUT"]);
|
||||
const PRISMA_ERROR_CODE_PATTERN = /^P\d{4}$/u;
|
||||
|
||||
export type SafeErrorLog = {
|
||||
errorName: string;
|
||||
errorCode?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Keeps provider, database, URL and PII details out of shared logs while
|
||||
* retaining a bounded error identity that is useful for aggregation.
|
||||
*/
|
||||
export function toSafeErrorLog(error: unknown): SafeErrorLog {
|
||||
if (!(error instanceof Error)) {
|
||||
return { errorName: "UnknownError" };
|
||||
}
|
||||
const rawCode = "code" in error ? (error as Error & { code?: unknown }).code : undefined;
|
||||
const errorCode = typeof rawCode === "string" && (PRISMA_ERROR_CODE_PATTERN.test(rawCode) || SAFE_NODE_ERROR_CODES.has(rawCode)) ? rawCode : undefined;
|
||||
return {
|
||||
errorName: SAFE_ERROR_NAMES.has(error.name) ? error.name : "Error",
|
||||
...(errorCode ? { errorCode } : {}),
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user