From af32c05a306a8e4e747c1b1f71ae0cd3522d4069 Mon Sep 17 00:00:00 2001 From: Darcy Ye Date: Wed, 22 Jan 2025 15:42:55 +0800 Subject: [PATCH] chore: update error message (#6968) --- .../core/src/queries/saml-application/index.ts | 14 +++++++++++++- .../core/src/routes/saml-application/anonymous.ts | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/core/src/queries/saml-application/index.ts b/packages/core/src/queries/saml-application/index.ts index df9f84c95..ba9a06a55 100644 --- a/packages/core/src/queries/saml-application/index.ts +++ b/packages/core/src/queries/saml-application/index.ts @@ -12,6 +12,8 @@ import type { CommonQueryMethods } from '@silverhand/slonik'; import { sql } from '@silverhand/slonik'; import { z } from 'zod'; +import RequestError from '#src/errors/RequestError/index.js'; +import assertThat from '#src/utils/assert-that.js'; import { convertToIdentifiers } from '#src/utils/sql.js'; const { table, fields } = convertToIdentifiers(Applications, true); @@ -70,7 +72,7 @@ const samlApplicationDetailsGuard = Applications.guard export const createSamlApplicationQueries = (pool: CommonQueryMethods) => { const getSamlApplicationDetailsById = async (id: string): Promise => { - const result = await pool.one(sql` + const result = await pool.maybeOne(sql` select ${fields.id} as id, ${fields.secret} as secret, ${fields.name} as name, ${fields.description} as description, ${fields.customData} as custom_data, ${fields.oidcClientMetadata} as oidc_client_metadata, ${samlApplicationConfigsFields.attributeMapping} as attribute_mapping, ${samlApplicationConfigsFields.entityId} as entity_id, ${samlApplicationConfigsFields.acsUrl} as acs_url, ${samlApplicationConfigsFields.encryption} as encryption, ${samlApplicationConfigsFields.nameIdFormat} as name_id_format, ${samlApplicationSecretsFields.privateKey} as private_key, ${samlApplicationSecretsFields.certificate} as certificate, ${samlApplicationSecretsFields.active} as active, ${samlApplicationSecretsFields.expiresAt} as expires_at from ${table} left join ${samlApplicationConfigsTable} on ${fields.id}=${samlApplicationConfigsFields.applicationId} @@ -78,6 +80,16 @@ export const createSamlApplicationQueries = (pool: CommonQueryMethods) => { where ${fields.id}=${id} and ${fields.type}=${ApplicationType.SAML} and ${samlApplicationSecretsFields.active}=true `); + assertThat( + result, + new RequestError( + { code: 'entity.not_found', status: 404 }, + { + message: `Can not find SAML application by ID (${id}) with active certificate.`, + } + ) + ); + return samlApplicationDetailsGuard.parse(result); }; diff --git a/packages/core/src/routes/saml-application/anonymous.ts b/packages/core/src/routes/saml-application/anonymous.ts index 8b972626d..201b7acac 100644 --- a/packages/core/src/routes/saml-application/anonymous.ts +++ b/packages/core/src/routes/saml-application/anonymous.ts @@ -67,7 +67,7 @@ export default function samlApplicationAnonymousRoutes {