mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-05-16 06:49:09 +02:00
improve logging
This commit is contained in:
@@ -171,7 +171,7 @@ export default class AnonymizedFile {
|
||||
if (this._file?.size && this._file?.size > config.MAX_FILE_SIZE) {
|
||||
throw new AnonymousError("file_too_big", {
|
||||
object: this,
|
||||
httpStatus: 403,
|
||||
httpStatus: 413,
|
||||
});
|
||||
}
|
||||
const content = await this.repository.source?.getFileContent(this);
|
||||
|
||||
@@ -59,6 +59,30 @@ export default class AnonymousError extends CustomError {
|
||||
return `GHDownload ${this.value.data.repoId}`;
|
||||
}
|
||||
if (typeof this.value === "string") return this.value;
|
||||
// For plain objects (typically request bodies passed in by route
|
||||
// handlers), pull out the diagnostic fingerprint instead of dumping
|
||||
// the entire body. Routes throw with `object: req.body`, which used
|
||||
// to bloat the log with the full JSON of options/source/etc — none
|
||||
// of which helps an operator triage the failure.
|
||||
if (typeof this.value === "object") {
|
||||
const v = this.value as Record<string, unknown>;
|
||||
const fingerprint: string[] = [];
|
||||
if (typeof v.repoId === "string") fingerprint.push(`repoId=${v.repoId}`);
|
||||
if (typeof v.fullName === "string") fingerprint.push(`fullName=${v.fullName}`);
|
||||
if (typeof v.repositoryFullName === "string")
|
||||
fingerprint.push(`pr=${v.repositoryFullName}`);
|
||||
if (typeof v.pullRequestId === "string" || typeof v.pullRequestId === "number")
|
||||
fingerprint.push(`prId=${v.pullRequestId}`);
|
||||
if (typeof v.gistId === "string") fingerprint.push(`gistId=${v.gistId}`);
|
||||
if (typeof v.username === "string") fingerprint.push(`user=${v.username}`);
|
||||
if (typeof v.conferenceID === "string")
|
||||
fingerprint.push(`conference=${v.conferenceID}`);
|
||||
if (fingerprint.length) return fingerprint.join(" ");
|
||||
// Fall back to a bounded, readable preview rather than a giant
|
||||
// escaped JSON blob. Keep it small so the rendered card stays tidy.
|
||||
const json = JSON.stringify(this.value);
|
||||
return json.length > 120 ? json.slice(0, 117) + "…" : json;
|
||||
}
|
||||
return JSON.stringify(this.value);
|
||||
} catch {
|
||||
return String(this.value);
|
||||
|
||||
+1
-1
@@ -154,7 +154,7 @@ export default class Gist {
|
||||
) {
|
||||
throw new AnonymousError("gist_not_ready", {
|
||||
object: this,
|
||||
httpStatus: 503,
|
||||
httpStatus: 425,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ export default class PullRequest {
|
||||
) {
|
||||
throw new AnonymousError("pull_request_not_ready", {
|
||||
object: this,
|
||||
httpStatus: 503,
|
||||
httpStatus: 425,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ export default class Repository {
|
||||
) {
|
||||
throw new AnonymousError("repository_not_ready", {
|
||||
object: this,
|
||||
httpStatus: 503,
|
||||
httpStatus: 425,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ export class GitHubRepository {
|
||||
}
|
||||
} catch (error) {
|
||||
throw new AnonymousError("repo_not_found", {
|
||||
httpStatus: (error as { status?: number }).status,
|
||||
httpStatus: (error as { status?: number }).status || 404,
|
||||
cause: error as Error,
|
||||
object: this,
|
||||
});
|
||||
|
||||
@@ -332,7 +332,7 @@ export default class GitHubStream extends GitHubBase {
|
||||
}
|
||||
logger.warn("getTree failed", serializeError(error));
|
||||
throw new AnonymousError("repo_not_found", {
|
||||
httpStatus: status || 500,
|
||||
httpStatus: status || 404,
|
||||
object: this.data,
|
||||
cause: error as Error,
|
||||
});
|
||||
|
||||
@@ -34,7 +34,7 @@ router.get(
|
||||
if (!(await repo.isReady())) {
|
||||
throw new AnonymousError("repository_not_ready", {
|
||||
object: repo,
|
||||
httpStatus: 503,
|
||||
httpStatus: 425,
|
||||
});
|
||||
}
|
||||
const f = new AnonymizedFile({
|
||||
|
||||
@@ -59,7 +59,7 @@ router.get(
|
||||
);
|
||||
}
|
||||
throw new AnonymousError("gist_not_ready", {
|
||||
httpStatus: 404,
|
||||
httpStatus: 425,
|
||||
object: gist,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ router.get(
|
||||
);
|
||||
}
|
||||
throw new AnonymousError("repository_not_ready", {
|
||||
httpStatus: 404,
|
||||
httpStatus: 425,
|
||||
object: repo,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ export function isOwnerCoauthorOrAdmin(repo: Repository, user: User) {
|
||||
if (repo.owner.id === user.model.id) return;
|
||||
if (isCoauthor(repo, user)) return;
|
||||
throw new AnonymousError("not_authorized", {
|
||||
httpStatus: 401,
|
||||
httpStatus: 403,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user