feat: introduce streamers that handle the stream and anonymization from github

This commit is contained in:
tdurieux
2024-04-03 11:13:01 +01:00
parent 73019c1b44
commit 4d12641c7e
64 changed files with 419 additions and 257 deletions
+53
View File
@@ -0,0 +1,53 @@
import { CustomError } from "ts-custom-error";
import AnonymizedFile from "./AnonymizedFile";
import Repository from "./Repository";
import GitHubBase from "./source/GitHubBase";
import { GitHubRepository } from "./source/GitHubRepository";
import User from "./User";
/**
* Custom error message
*/
export default class AnonymousError extends CustomError {
value?: any;
httpStatus?: number;
cause?: Error;
constructor(
message: string,
opt?: {
httpStatus?: number;
cause?: Error;
object?: any;
}
) {
super(message);
this.value = opt?.object;
this.httpStatus = opt?.httpStatus;
this.cause = opt?.cause;
}
toString(): string {
let out = "";
let detail = this.value ? JSON.stringify(this.value) : null;
if (this.value instanceof Repository) {
detail = this.value.repoId;
} else if (this.value instanceof AnonymizedFile) {
detail = `/r/${this.value.repository.repoId}/${this.value.anonymizedPath}`;
} else if (this.value instanceof GitHubRepository) {
detail = `${this.value.fullName}`;
} else if (this.value instanceof User) {
detail = `${this.value.username}`;
} else if (this.value instanceof GitHubBase) {
detail = `GHDownload ${this.value.data.repoId}`;
}
out += this.message;
if (detail) {
out += `: ${detail}`;
}
if (this.cause) {
out += `\n\tCause by ${this.cause}\n${this.cause.stack}`;
}
return out;
}
}