Skip to content

Commit

Permalink
fix(shared): decode error details from path reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
ascariandrea committed Feb 2, 2025
1 parent ff1b7cd commit 4ea7f6c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
20 changes: 13 additions & 7 deletions packages/@liexp/backend/src/io/ENV.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ export const DATABASE_ENV = t.intersection(
"DATABASE_ENV",
),
t.union([
t.strict({
DB_SSL_MODE: t.literal("require"),
DB_SSL_CERT_PATH: t.string,
}),
t.strict({
DB_SSL_MODE: t.literal("off"),
}),
t.strict(
{
DB_SSL_MODE: t.literal("require"),
DB_SSL_CERT_PATH: t.string,
},
"DB_SSL_REQUIRE",
),
t.strict(
{
DB_SSL_MODE: t.literal("off"),
},
"DB_SSL_OFF",
),
]),
],
"DB_ENV",
Expand Down
4 changes: 3 additions & 1 deletion packages/@liexp/shared/src/io/http/Error/DecodeError.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { fp } from "@liexp/core/lib/fp/index.js";
import type * as t from "io-ts";
import { PathReporter } from "io-ts/lib/PathReporter.js";
import { IOError } from "ts-io-error";

export class _DecodeError extends IOError {
Expand All @@ -9,7 +11,7 @@ export const DecodeError = {
of: (message: string, errors: t.Errors): _DecodeError => {
return new _DecodeError(message, {
kind: "DecodingError",
errors: errors,
errors: PathReporter.report(fp.E.left(errors)),
});
},
};
3 changes: 2 additions & 1 deletion scripts/docker-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ scp ./deploy/gh-token.txt $SSH_DOMAIN:docker-app/gh-token.txt
scp ./deploy/ai-bot.config.json $SSH_DOMAIN:docker-app/ai-bot.config.json
scp ./deploy/compose.yml $SSH_DOMAIN:docker-app/compose.yml

scp -r ./services/api/certs/ $SSH_DOMAIN:docker-app/certs/
scp -r ./deploy/certs/ $SSH_DOMAIN:docker-app/certs/
mkdir -p ./services/api/config/
scp -r ./services/api/config/ $SSH_DOMAIN:docker-app/config/

scp -r ./resources/nginx/snippets/ssl-params.conf $SSH_DOMAIN:/etc/nginx/snippets/ssl-params.conf
Expand Down
17 changes: 5 additions & 12 deletions services/api/src/io/ControllerError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { IOErrorSchema } from "@liexp/shared/lib/io/http/Error/IOError.js";
import { type HTTPError } from "@liexp/shared/lib/providers/http/http.provider.js";
import { UnauthorizedError } from "express-jwt";
import { pipe } from "fp-ts/lib/function.js";
import { failure } from "io-ts/lib/PathReporter.js";

export type ControllerError =
| HTTPError
Expand Down Expand Up @@ -117,21 +116,15 @@ export const toAPIError = (err: ControllerError): APIError => {
};
}

if (err.details?.kind === "DecodingError") {
if (
err.name === _DecodeError.name ||
err.details?.kind === "DecodingError"
) {
return {
status: 400,
name: "APIError",
message: err.message,
details: failure((err.details as any).errors),
};
}

if (err.name === _DecodeError.name) {
return {
status: 400,
name: "APIError",
message: err.message,
details: failure((err.details as any).errors),
details: (err.details as any).errors,
};
}

Expand Down

0 comments on commit 4ea7f6c

Please sign in to comment.