fix(http-request-action): pretty-print JSON errors in test HTTP requeset hook (#16387)

Before:
<img width="415" height="319" alt="Screenshot from 2025-12-08 09-00-48"
src="https://github.com/user-attachments/assets/bd99cf74-d278-4344-a3c2-e7740d7d058b"
/>

After:
<img width="399" height="371" alt="Screenshot from 2025-12-08 08-59-05"
src="https://github.com/user-attachments/assets/5c75bded-1632-4a9a-9b51-ed3c83f36b3b"
/>

fixes #16243

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Mikhail Wahib
2025-12-08 19:23:55 +02:00
committed by GitHub
parent d7dbb87a8f
commit 4fe9e57847
3 changed files with 19 additions and 6 deletions
@@ -3,6 +3,7 @@ import {
WorkflowStepExecutionResult,
} from '@/workflow/components/WorkflowStepExecutionResult';
import type { HttpRequestTestData } from '@/workflow/workflow-steps/workflow-actions/http-request-action/types/HttpRequestTestData';
import { t } from '@lingui/core/macro';
export const HttpRequestExecutionResult = ({
httpRequestTestData,
@@ -45,8 +46,8 @@ export const HttpRequestExecutionResult = ({
isSuccess &&
Object.keys(httpRequestTestData.output.headers || {}).length > 0
? `${Object.keys(httpRequestTestData.output.headers || {}).length} headers received`
: isError && httpRequestTestData.output.error
? httpRequestTestData.output.error
: isError
? t`An error occurred`
: undefined,
};
@@ -397,7 +397,10 @@ describe('useTestHttpRequest', () => {
});
expect(result.current.httpRequestTestData.output?.error).toBe(
'{"code":"ERR_CONNECTION_REFUSED","details":"Connection refused"}',
`{
"code": "ERR_CONNECTION_REFUSED",
"details": "Connection refused"
}`,
);
});
@@ -9,7 +9,7 @@ import { useMutation } from '@apollo/client';
import { isObject, isString } from '@sniptt/guards';
import { useState } from 'react';
import { useRecoilState } from 'recoil';
import { isDefined, resolveInput } from 'twenty-shared/utils';
import { isDefined, parseJson, resolveInput } from 'twenty-shared/utils';
import {
type TestHttpRequestInput,
type TestHttpRequestMutation,
@@ -125,9 +125,18 @@ export const useTestHttpRequest = (actionId: string) => {
}
} catch (error) {
const duration = Date.now() - startTime;
const errorMessage =
const rawErrorMessage =
error instanceof Error ? error.message : 'HTTP request failed';
const jsonParsedErrorMessage = parseJson(rawErrorMessage);
const errorMessage = isDefined(jsonParsedErrorMessage)
? JSON.stringify(jsonParsedErrorMessage, null, 2)
: rawErrorMessage;
const language = isDefined(jsonParsedErrorMessage) ? 'json' : 'plaintext';
setHttpRequestTestData((prev) => ({
...prev,
output: {
@@ -138,7 +147,7 @@ export const useTestHttpRequest = (actionId: string) => {
duration,
error: errorMessage,
},
language: 'plaintext',
language,
}));
} finally {
setIsTesting(false);