Skip to content

Commit

Permalink
Fix/56 unexpected error catched (#58)
Browse files Browse the repository at this point in the history
* fix: add AllServiceErrors constant and check if error must me handled

* fix: apply updated code gen for codedeploy client

* feat: use Effect.Tag instead of Context.GenericTag for service

* feat: use Effect.Tag instead of Context.GenericTag for service

* feat: upgrade other packages
  • Loading branch information
floydspace authored Sep 1, 2024
1 parent 85be1b5 commit 888dc8c
Show file tree
Hide file tree
Showing 52 changed files with 4,456 additions and 3,008 deletions.
6 changes: 6 additions & 0 deletions .changeset/blue-ghosts-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@effect-aws/client-secrets-manager": minor
"@effect-aws/client-codedeploy": minor
---

use Effect.Tag instead of Context.GenericTag for service, handle only known errors
12 changes: 12 additions & 0 deletions .changeset/chilled-rabbits-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@effect-aws/client-api-gateway-management-api": minor
"@effect-aws/client-elasticache": minor
"@effect-aws/client-eventbridge": minor
"@effect-aws/client-lambda": minor
"@effect-aws/client-iam": minor
"@effect-aws/client-sfn": minor
"@effect-aws/client-sns": minor
"@effect-aws/client-sqs": minor
---

use Effect.Tag instead of Context.GenericTag for service, upgrade sdk, handle only known errors
5 changes: 5 additions & 0 deletions .changeset/young-kangaroos-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect-aws/client-dynamodb": minor
---

use Effect.Tag instead of Context.GenericTag for service, upgrade sdk, handle only known errors
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import * as Context from "effect/Context";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import {
ApiGatewayManagementApiClientInstanceConfig,
DefaultApiGatewayManagementApiClientConfigLayer,
ApiGatewayManagementApiClientInstanceConfig,
} from "./ApiGatewayManagementApiClientInstanceConfig";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,21 @@ export const makeDefaultApiGatewayManagementApiClientInstanceConfig: Effect.Effe

return {
logger: {
info: (m) => Effect.logInfo(m).pipe(runSync),
warn: (m) => Effect.logWarning(m).pipe(runSync),
error: (m) => Effect.logError(m).pipe(runSync),
debug: (m) => Effect.logDebug(m).pipe(runSync),
trace: (m) => Effect.logTrace(m).pipe(runSync),
info(m) {
Effect.logInfo(m).pipe(runSync);
},
warn(m) {
Effect.logWarning(m).pipe(runSync);
},
error(m) {
Effect.logError(m).pipe(runSync);
},
debug(m) {
Effect.logDebug(m).pipe(runSync);
},
trace(m) {
Effect.logTrace(m).pipe(runSync);
},
},
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@
import {
ApiGatewayManagementApiServiceException,
DeleteConnectionCommand,
DeleteConnectionCommandInput,
DeleteConnectionCommandOutput,
type DeleteConnectionCommandInput,
type DeleteConnectionCommandOutput,
GetConnectionCommand,
GetConnectionCommandInput,
GetConnectionCommandOutput,
type GetConnectionCommandInput,
type GetConnectionCommandOutput,
PostToConnectionCommand,
PostToConnectionCommandInput,
PostToConnectionCommandOutput,
type PostToConnectionCommandInput,
type PostToConnectionCommandOutput,
} from "@aws-sdk/client-apigatewaymanagementapi";
import { HttpHandlerOptions as __HttpHandlerOptions } from "@aws-sdk/types";
import { Context, Data, Effect, Layer, Record } from "effect";
import { type HttpHandlerOptions as __HttpHandlerOptions } from "@aws-sdk/types";
import { Data, Effect, Layer, Record } from "effect";
import {
ApiGatewayManagementApiClientInstance,
ApiGatewayManagementApiClientInstanceLayer,
} from "./ApiGatewayManagementApiClientInstance";
import { DefaultApiGatewayManagementApiClientConfigLayer } from "./ApiGatewayManagementApiClientInstanceConfig";
import {
AllServiceErrors,
ForbiddenError,
GoneError,
LimitExceededError,
Expand All @@ -35,11 +36,7 @@ const commands = {
PostToConnectionCommand,
};

/**
* @since 1.0.0
* @category models
*/
export interface ApiGatewayManagementApiService {
interface ApiGatewayManagementApiService$ {
readonly _: unique symbol;

/**
Expand All @@ -50,7 +47,7 @@ export interface ApiGatewayManagementApiService {
options?: __HttpHandlerOptions,
): Effect.Effect<
DeleteConnectionCommandOutput,
SdkError | GoneError | ForbiddenError | LimitExceededError
SdkError | ForbiddenError | GoneError | LimitExceededError
>;

/**
Expand All @@ -61,7 +58,7 @@ export interface ApiGatewayManagementApiService {
options?: __HttpHandlerOptions,
): Effect.Effect<
GetConnectionCommandOutput,
SdkError | GoneError | ForbiddenError | LimitExceededError
SdkError | ForbiddenError | GoneError | LimitExceededError
>;

/**
Expand All @@ -73,21 +70,20 @@ export interface ApiGatewayManagementApiService {
): Effect.Effect<
PostToConnectionCommandOutput,
| SdkError
| GoneError
| ForbiddenError
| GoneError
| LimitExceededError
| PayloadTooLargeError
>;
}

/**
* @since 1.0.0
* @category tags
* @category models
*/
export const ApiGatewayManagementApiService =
Context.GenericTag<ApiGatewayManagementApiService>(
"@effect-aws/client-api-gateway-management-api/ApiGatewayManagementApiService",
);
export class ApiGatewayManagementApiService extends Effect.Tag(
"@effect-aws/client-api-gateway-management-api/ApiGatewayManagementApiService",
)<ApiGatewayManagementApiService, ApiGatewayManagementApiService$>() {}

/**
* @since 1.0.0
Expand All @@ -102,7 +98,10 @@ export const makeApiGatewayManagementApiService = Effect.gen(function* (_) {
Effect.tryPromise({
try: () => client.send(new CommandCtor(args), options ?? {}),
catch: (e) => {
if (e instanceof ApiGatewayManagementApiServiceException) {
if (
e instanceof ApiGatewayManagementApiServiceException &&
AllServiceErrors.includes(e.name)
) {
const ServiceException = Data.tagged<
TaggedException<ApiGatewayManagementApiServiceException>
>(e.name);
Expand All @@ -129,7 +128,7 @@ export const makeApiGatewayManagementApiService = Effect.gen(function* (_) {
"",
);
return { ...acc, [methodName]: methodImpl };
}, {}) as ApiGatewayManagementApiService;
}, {}) as ApiGatewayManagementApiService$;
});

/**
Expand Down
8 changes: 8 additions & 0 deletions packages/client-api-gateway-management-api/src/Errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import type {
} from "@aws-sdk/client-apigatewaymanagementapi";
import { Data } from "effect";

export const AllServiceErrors = [
"ForbiddenException",
"GoneException",
"LimitExceededException",
"PayloadTooLargeException",
];

export type TaggedException<T extends { name: string }> = T & {
readonly _tag: T["name"];
};
Expand All @@ -14,5 +21,6 @@ export type ForbiddenError = TaggedException<ForbiddenException>;
export type GoneError = TaggedException<GoneException>;
export type LimitExceededError = TaggedException<LimitExceededException>;
export type PayloadTooLargeError = TaggedException<PayloadTooLargeException>;

export type SdkError = TaggedException<Error & { name: "SdkError" }>;
export const SdkError = Data.tagged<SdkError>("SdkError");
2 changes: 1 addition & 1 deletion packages/client-api-gateway-management-api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from "./Errors";
export * from "./ApiGatewayManagementApiClientInstance";
export * from "./ApiGatewayManagementApiClientInstanceConfig";
export * from "./ApiGatewayManagementApiService";
export * from "./Errors";
Loading

0 comments on commit 888dc8c

Please sign in to comment.