Skip to content

Commit

Permalink
fix: linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
arcogabbo committed Oct 14, 2024
1 parent 4dec82d commit df7b75f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
28 changes: 8 additions & 20 deletions utils/pdv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { RedisClientType } from "redis";
import { Second } from "@pagopa/ts-commons/lib/units";
import { PdvTokenizerClient } from "./pdvTokenizerClient";
import { sha256 } from "./crypto";
import { PDVIdPrefix, sendSampledRedisError } from "./redis";
import {
PDVIdPrefix,
sendSampledRedisCommandError,
sendSampledRedisNetworkError
} from "./redis";

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export type PdvDependencies = {
Expand Down Expand Up @@ -64,7 +68,7 @@ const obtainTokenFromPDV: (
TE.chainFirstW(pdvId =>
pipe(
deps.redisClientTask,
sendSampledRedisError(deps.appInsightsTelemetryClient),
sendSampledRedisNetworkError(deps.appInsightsTelemetryClient),
TE.chain(redisClient =>
pipe(
TE.tryCatch(
Expand All @@ -76,15 +80,7 @@ const obtainTokenFromPDV: (
),
E.toError
),
TE.mapLeft(error => {
deps.appInsightsTelemetryClient.trackEvent({
name: "fn-elt.getPdvId.redis.command.error",
properties: {
error_message: error.message
}
});
return error;
})
sendSampledRedisCommandError(deps.appInsightsTelemetryClient)
)
),
TE.map(_ => void 0),
Expand All @@ -110,15 +106,7 @@ export const getPdvId: (
() => redisClient.get(`${PDVIdPrefix}${fiscalCode}`),
E.toError
),
TE.mapLeft(error => {
deps.appInsightsTelemetryClient.trackEvent({
name: "fn-elt.getPdvId.redis.command.error",
properties: {
error_message: error.message
}
});
return error;
}),
sendSampledRedisCommandError(deps.appInsightsTelemetryClient),
TE.chainEitherKW(NonEmptyString.decode)
)
),
Expand Down
20 changes: 19 additions & 1 deletion utils/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export const falsyResponseToErrorAsync = (error: Error) => (
TE.chain(value => (value ? TE.right(value) : TE.left(error)))
);

export const sendSampledRedisError = (
export const sendSampledRedisNetworkError = (
appInsightsTelemetryClient: TelemetryClient
) => (
redisTask: TE.TaskEither<Error, redis.RedisClientType>
Expand All @@ -149,3 +149,21 @@ export const sendSampledRedisError = (
return err;
})
);

export const sendSampledRedisCommandError = (
appInsightsTelemetryClient: TelemetryClient
) => (
command: TE.TaskEither<Error, string | null>
): TE.TaskEither<Error, string | null> =>
pipe(
command,
TE.mapLeft(error => {
appInsightsTelemetryClient.trackEvent({
name: "fn-elt.getPdvId.redis.command.error",
properties: {
error_message: error.message
}
});
return error;
})
);

0 comments on commit df7b75f

Please sign in to comment.