Skip to content

Commit

Permalink
fix: remove redundant checks for known errors
Browse files Browse the repository at this point in the history
  • Loading branch information
aubin-tchoi committed Nov 26, 2024
1 parent 3d7fac2 commit b64d2eb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 50 deletions.
29 changes: 0 additions & 29 deletions connectors/src/connectors/zendesk/lib/zendesk_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import { createClient } from "node-zendesk";
import type {
ZendeskFetchedArticle,
ZendeskFetchedCategory,
ZendeskFetchedSection,
ZendeskFetchedTicket,
ZendeskFetchedUser,
} from "@connectors/@types/node-zendesk";
import { isNodeZendeskForbiddenError } from "@connectors/connectors/zendesk/lib/errors";
import { ExternalOAuthTokenError } from "@connectors/lib/error";
import logger from "@connectors/logger/logger";
import type { ZendeskCategoryResource } from "@connectors/resources/zendesk_resources";
Expand Down Expand Up @@ -365,30 +363,3 @@ export async function fetchZendeskCurrentUser({
const data = await response.json();
return data.user;
}

/**
* Fetches the Section and the User for an article.
*/
export async function fetchArticleMetadata(
zendeskApiClient: Client,
article: ZendeskFetchedArticle
): Promise<{ section: ZendeskFetchedSection; user: ZendeskFetchedUser }> {
try {
const { result: section } = await zendeskApiClient.helpcenter.sections.show(
article.section_id
);
const { result: user } = await zendeskApiClient.users.show(
article.author_id
);
return { section, user };
} catch (e) {
logger.error(
{ articleId: article.id, error: e },
"[Zendesk] Error fetching article metadata"
);
if (isNodeZendeskForbiddenError(e)) {
throw new ExternalOAuthTokenError(e);
}
throw e;
}
}
22 changes: 5 additions & 17 deletions connectors/src/connectors/zendesk/temporal/activities.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { ModelId } from "@dust-tt/types";

import { isNodeZendeskForbiddenError } from "@connectors/connectors/zendesk/lib/errors";
import { syncArticle } from "@connectors/connectors/zendesk/lib/sync_article";
import { syncCategory } from "@connectors/connectors/zendesk/lib/sync_category";
import { syncTicket } from "@connectors/connectors/zendesk/lib/sync_ticket";
Expand All @@ -15,7 +14,6 @@ import {
import { ZENDESK_BATCH_SIZE } from "@connectors/connectors/zendesk/temporal/config";
import { dataSourceConfigFromConnector } from "@connectors/lib/api/data_source_config";
import { concurrentExecutor } from "@connectors/lib/async_utils";
import { ExternalOAuthTokenError } from "@connectors/lib/error";
import { ZendeskTimestampCursor } from "@connectors/lib/models/zendesk";
import { syncStarted, syncSucceeded } from "@connectors/lib/sync_status";
import { heartbeat } from "@connectors/lib/temporal";
Expand Down Expand Up @@ -332,21 +330,11 @@ export async function syncZendeskArticleBatchActivity({
`[Zendesk] Processing ${articles.length} articles in batch`
);

let sections;
let users;
try {
sections =
await zendeskApiClient.helpcenter.sections.listByCategory(categoryId);
const { result: usersResult } = await zendeskApiClient.users.showMany(
articles.map((article) => article.author_id)
);
users = usersResult;
} catch (e) {
if (isNodeZendeskForbiddenError(e)) {
throw new ExternalOAuthTokenError(e);
}
throw e;
}
const sections =
await zendeskApiClient.helpcenter.sections.listByCategory(categoryId);
const { result: users } = await zendeskApiClient.users.showMany(
articles.map((article) => article.author_id)
);

await concurrentExecutor(
articles,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { getZendeskSubdomainAndAccessToken } from "@connectors/connectors/zendes
import {
changeZendeskClientSubdomain,
createZendeskClient,
fetchArticleMetadata,
fetchRecentlyUpdatedArticles,
fetchRecentlyUpdatedTickets,
} from "@connectors/connectors/zendesk/lib/zendesk_api";
Expand Down Expand Up @@ -113,9 +112,10 @@ export async function syncZendeskArticleUpdateBatchActivity({
await concurrentExecutor(
articles,
async (article) => {
const { section, user } = await fetchArticleMetadata(
zendeskApiClient,
article
const { result: section } =
await zendeskApiClient.helpcenter.sections.show(article.section_id);
const { result: user } = await zendeskApiClient.users.show(
article.author_id
);

if (section.category_id) {
Expand Down

0 comments on commit b64d2eb

Please sign in to comment.