Skip to content

Commit

Permalink
bug #11 Fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
darsan-in committed Jun 22, 2024
1 parent fc06356 commit 707307d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
5 changes: 5 additions & 0 deletions lib/gindex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ export function lastSubmissionStatusGAPI(): Promise<sitemapMetaOptions> {
"submittedSitemap",
) as string;

if (!lastSubmittedURL) {
console.log("Record of submission not found");
process.exit(1);
}

const jwtClient = new google.auth.JWT({
keyFile: constants.serviceAccountFile,
scopes: ["https://www.googleapis.com/auth/webmasters"],
Expand Down
33 changes: 27 additions & 6 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,20 @@ export function convertTimeinCTZone(ISOTime: string): string {
export function lastStateWriter(
newObject: Partial<ranStatusFileStructute>,
): void {
const previousDataObject: ranStatusFileStructute = JSON.parse(
readFileSync(constants.ranStatusFile, { encoding: "utf8" }),
);
let previousDataObject: ranStatusFileStructute;
try {
previousDataObject = JSON.parse(
readFileSync(constants.ranStatusFile, { encoding: "utf8" }),
);
} catch (err: any) {
if (err.code === "ENOENT") {
previousDataObject = {} as ranStatusFileStructute;
} else {
console.log("Unexpected error ", err);
process.exit(1);
}
}

const updatedDataObject: ranStatusFileStructute = {
...previousDataObject,
...newObject,
Expand All @@ -366,8 +377,18 @@ export function lastStateWriter(
export function lastStateReader(
keyName: lastStateKeyNames,
): string | number {
const dataObject: ranStatusFileStructute = JSON.parse(
readFileSync(constants.ranStatusFile, { encoding: "utf8" }),
);
let dataObject: ranStatusFileStructute;
try {
dataObject = JSON.parse(
readFileSync(constants.ranStatusFile, { encoding: "utf8" }),
);
} catch (err: any) {
if (err.code === "ENOENT") {
return 0;
} else {
console.log("Unexpected error ", err);
process.exit(1);
}
}
return dataObject[keyName];
}

0 comments on commit 707307d

Please sign in to comment.