Skip to content

Commit

Permalink
feat: handle errors
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyreilly committed Jan 2, 2024
1 parent c7af5a1 commit 120842f
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 23 deletions.
30 changes: 22 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34979,7 +34979,7 @@ ${responseText}`);
}
}
function processValidationResult(validationResult) {
const seeMore = `For more details see https://validator.schema.org/#url=${encodeURIComponent(validationResult.url)}`;
const seeMore = seeMoreMaker(validationResult.url);
if (validationResult.numObjects === 0) {
return {
success: false,
Expand All @@ -35006,6 +35006,9 @@ ${seeMore}
`,
};
}
function seeMoreMaker(url) {
return `For more details see https://validator.schema.org/#url=${encodeURIComponent(url)}`;
}

;// CONCATENATED MODULE: ./src/main.ts

Expand All @@ -35017,13 +35020,24 @@ async function run() {
const results = [];
for (const url of urls) {
console.log(`Validating ${url} for structured data...`);
const validationResult = processValidationResponse(await getValidationResponse(url));
const processedValidationResult = processValidationResult(validationResult);
results.push({
url,
// validationResult,
processedValidationResult,
});
try {
const validationResult = processValidationResponse(await getValidationResponse(url));
const processedValidationResult = processValidationResult(validationResult);
results.push({
url,
processedValidationResult,
});
}
catch (err) {
console.error(`Failed to validate ${url}`, err);
results.push({
url,
processedValidationResult: {
success: false,
resultText: `Failed to validate ${url}. ${seeMoreMaker(url)}`,
},
});
}
}
core.setOutput("results", results);
if (results.every((result) => result.processedValidationResult.success)) {
Expand Down
2 changes: 1 addition & 1 deletion dist/main.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/validate.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ import { type ValidationResult } from "./validationResult.js";
export declare function getValidationResponse(url: string): Promise<string>;
export declare function processValidationResponse(responseText: string): ValidationResult;
export declare function processValidationResult(validationResult: ValidationResult): ProcessedValidationResult;
export declare function seeMoreMaker(url: string): string;
2 changes: 1 addition & 1 deletion dist/validate.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 21 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
processValidationResult,
processValidationResponse,
getValidationResponse,
seeMoreMaker,
} from "./validate.js";
import type { Result } from "./validationResult.js";

Expand All @@ -15,17 +16,27 @@ export async function run(): Promise<void> {
for (const url of urls) {
console.log(`Validating ${url} for structured data...`);

const validationResult = processValidationResponse(
await getValidationResponse(url),
);
const processedValidationResult =
processValidationResult(validationResult);
try {
const validationResult = processValidationResponse(
await getValidationResponse(url),
);
const processedValidationResult =
processValidationResult(validationResult);

results.push({
url,
// validationResult,
processedValidationResult,
});
results.push({
url,
processedValidationResult,
});
} catch (err) {
console.error(`Failed to validate ${url}`, err);
results.push({
url,
processedValidationResult: {
success: false,
resultText: `Failed to validate ${url}. ${seeMoreMaker(url)}`,
},
});
}
}

core.setOutput("results", results);
Expand Down
10 changes: 7 additions & 3 deletions src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ ${responseText}`,
export function processValidationResult(
validationResult: ValidationResult,
): ProcessedValidationResult {
const seeMore = `For more details see https://validator.schema.org/#url=${encodeURIComponent(
validationResult.url,
)}`;
const seeMore = seeMoreMaker(validationResult.url);

if (validationResult.numObjects === 0) {
return {
Expand Down Expand Up @@ -109,3 +107,9 @@ ${seeMore}
`,
};
}

export function seeMoreMaker(url: string) {
return `For more details see https://validator.schema.org/#url=${encodeURIComponent(
url,
)}`;
}

0 comments on commit 120842f

Please sign in to comment.