From e34cfd812a135bd943d002a08174f16d211e92a9 Mon Sep 17 00:00:00 2001 From: Darcy Ye Date: Sat, 30 Mar 2024 10:10:03 +0800 Subject: [PATCH] chore(core): update GET /configs/jwt-customizer/:tokenPath API error handling (#5595) --- packages/core/src/libraries/logto-config.ts | 8 +++----- .../integration-tests/src/tests/api/logto-config.test.ts | 8 ++++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/core/src/libraries/logto-config.ts b/packages/core/src/libraries/logto-config.ts index 0e4f4ce4b9c..4ecd0e11a00 100644 --- a/packages/core/src/libraries/logto-config.ts +++ b/packages/core/src/libraries/logto-config.ts @@ -1,10 +1,10 @@ import { - LogtoConfigs, cloudApiIndicator, cloudConnectionDataGuard, logtoOidcConfigGuard, LogtoOidcConfigKey, jwtCustomizerConfigGuard, + LogtoConfigs, } from '@logto/schemas'; import type { LogtoOidcConfigType, LogtoJwtTokenKey, CloudConnectionData } from '@logto/schemas'; import chalk from 'chalk'; @@ -13,10 +13,8 @@ import { z, ZodError } from 'zod'; import RequestError from '#src/errors/RequestError/index.js'; import type Queries from '#src/tenants/Queries.js'; import { consoleLog } from '#src/utils/console.js'; -import { convertToIdentifiers } from '#src/utils/sql.js'; export type LogtoConfigLibrary = ReturnType; -const { table } = convertToIdentifiers(LogtoConfigs); export const createLogtoConfigLibrary = ({ logtoConfigs: { @@ -87,8 +85,8 @@ export const createLogtoConfigLibrary = ({ // If the record does not exist (`rows` is empty) if (rows.length === 0) { throw new RequestError({ - code: 'entity.not_exists', - name: table, + code: 'entity.not_exists_with_id', + name: LogtoConfigs.tableSingular, id: key, status: 404, }); diff --git a/packages/integration-tests/src/tests/api/logto-config.test.ts b/packages/integration-tests/src/tests/api/logto-config.test.ts index acd566c8d3c..3934484fa45 100644 --- a/packages/integration-tests/src/tests/api/logto-config.test.ts +++ b/packages/integration-tests/src/tests/api/logto-config.test.ts @@ -140,7 +140,7 @@ describe('admin console sign-in experience', () => { }; await expectRejects(getJwtCustomizer('access-token'), { - code: 'entity.not_exists', + code: 'entity.not_exists_with_id', status: 404, }); await expectRejects(deleteJwtCustomizer('access-token'), { @@ -163,7 +163,7 @@ describe('admin console sign-in experience', () => { ); await expect(deleteJwtCustomizer('access-token')).resolves.not.toThrow(); await expectRejects(getJwtCustomizer('access-token'), { - code: 'entity.not_exists', + code: 'entity.not_exists_with_id', status: 404, }); }); @@ -176,7 +176,7 @@ describe('admin console sign-in experience', () => { }; await expectRejects(getJwtCustomizer('client-credentials'), { - code: 'entity.not_exists', + code: 'entity.not_exists_with_id', status: 404, }); await expectRejects(deleteJwtCustomizer('client-credentials'), { @@ -202,7 +202,7 @@ describe('admin console sign-in experience', () => { ); await expect(deleteJwtCustomizer('client-credentials')).resolves.not.toThrow(); await expectRejects(getJwtCustomizer('client-credentials'), { - code: 'entity.not_exists', + code: 'entity.not_exists_with_id', status: 404, }); });