Skip to content

Commit 0bf4188

Browse files
committed
fix: Do not log error when fetching non-existing Actor
1 parent 2251497 commit 0bf4188

File tree

1 file changed

+38
-19
lines changed

1 file changed

+38
-19
lines changed

src/utils/actor-details.ts

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { Actor, Build } from 'apify-client';
22

3+
import log from '@apify/log';
4+
35
import type { ApifyClient } from '../apify-client.js';
46
import { filterSchemaProperties, shortenProperties } from '../tools/utils.js';
57
import type { IActorInputSchema } from '../types.js';
@@ -15,23 +17,40 @@ export interface ActorDetailsResult {
1517
}
1618

1719
export async function fetchActorDetails(apifyClient: ApifyClient, actorName: string): Promise<ActorDetailsResult | null> {
18-
const [actorInfo, buildInfo]: [Actor | undefined, Build | undefined] = await Promise.all([
19-
apifyClient.actor(actorName).get(),
20-
apifyClient.actor(actorName).defaultBuild().then(async (build) => build.get()),
21-
]);
22-
if (!actorInfo || !buildInfo || !buildInfo.actorDefinition) return null;
23-
const inputSchema = (buildInfo.actorDefinition.input || {
24-
type: 'object',
25-
properties: {},
26-
}) as IActorInputSchema;
27-
inputSchema.properties = filterSchemaProperties(inputSchema.properties);
28-
inputSchema.properties = shortenProperties(inputSchema.properties);
29-
const actorCard = formatActorToActorCard(actorInfo);
30-
return {
31-
actorInfo,
32-
buildInfo,
33-
actorCard,
34-
inputSchema,
35-
readme: buildInfo.actorDefinition.readme || 'No README provided.',
36-
};
20+
try {
21+
const [actorInfo, buildInfo]: [Actor | undefined, Build | undefined] = await Promise.all([
22+
apifyClient.actor(actorName).get(),
23+
apifyClient.actor(actorName).defaultBuild().then(async (build) => build.get()),
24+
]);
25+
if (!actorInfo || !buildInfo || !buildInfo.actorDefinition) return null;
26+
const inputSchema = (buildInfo.actorDefinition.input || {
27+
type: 'object',
28+
properties: {},
29+
}) as IActorInputSchema;
30+
inputSchema.properties = filterSchemaProperties(inputSchema.properties);
31+
inputSchema.properties = shortenProperties(inputSchema.properties);
32+
const actorCard = formatActorToActorCard(actorInfo);
33+
return {
34+
actorInfo,
35+
buildInfo,
36+
actorCard,
37+
inputSchema,
38+
readme: buildInfo.actorDefinition.readme || 'No README provided.',
39+
};
40+
} catch (error) {
41+
// Check if it's a 404 error (actor not found) - this is expected
42+
const is404 = typeof error === 'object'
43+
&& error !== null
44+
&& 'statusCode' in error
45+
&& (error as { statusCode?: number }).statusCode === 404;
46+
47+
if (is404) {
48+
// Log 404 errors at info level since they're expected (user may query non-existent actors)
49+
log.info(`Actor '${actorName}' not found`, { actorName });
50+
} else {
51+
// Log other errors at error level
52+
log.error(`Failed to fetch actor details for '${actorName}'`, { actorName, error });
53+
}
54+
return null;
55+
}
3756
}

0 commit comments

Comments
 (0)