From 378c75116cb39c8f99f0c1aaebb735ec754476d3 Mon Sep 17 00:00:00 2001 From: Darcy Ye Date: Sat, 9 Jul 2022 00:13:06 +0800 Subject: [PATCH] refactor(core): refactor connector general error message (#1501) --- packages/core/src/middleware/koa-connector-error-handler.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/core/src/middleware/koa-connector-error-handler.ts b/packages/core/src/middleware/koa-connector-error-handler.ts index 5907fb048..894971baf 100644 --- a/packages/core/src/middleware/koa-connector-error-handler.ts +++ b/packages/core/src/middleware/koa-connector-error-handler.ts @@ -1,4 +1,5 @@ import { ConnectorError, ConnectorErrorCodes } from '@logto/connector-types'; +import { conditional } from '@silverhand/essentials'; import { Middleware } from 'koa'; import { z } from 'zod'; @@ -17,7 +18,7 @@ export default function koaConnectorErrorHandler(): Middleware const errorDescriptionGuard = z.object({ errorDescription: z.string() }); const result = errorDescriptionGuard.safeParse(data); - const errorMessage = result.success ? result.data.errorDescription : undefined; + const errorMessage = conditional(result.success && '\n' + result.data.errorDescription); switch (code) { case ConnectorErrorCodes.InsufficientRequestParameters: @@ -90,7 +91,7 @@ export default function koaConnectorErrorHandler(): Middleware { code: 'connector.general', status: 500, - errorDescription: errorMessage ? '\n' + errorMessage : undefined, + errorDescription: errorMessage, }, data );