Skip to content

Commit dcf367f

Browse files
committed
fix(journey-client): treat object error.data as LoginFailure and remove isStepLike
1 parent 6708610 commit dcf367f

2 files changed

Lines changed: 5 additions & 36 deletions

File tree

packages/journey-client/src/lib/journey.utils.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,11 @@ describe('resolveJourneyResult - no_response_data', () => {
5656
});
5757

5858
describe('toJourneyResult', () => {
59-
it('returns request_failed GenericError for FetchBaseQueryError without Step payload', () => {
59+
it('returns LoginFailure when FetchBaseQueryError has an object payload', () => {
6060
const result = resolveJourneyResult(undefined, { status: 500, data: { foo: 'bar' } });
6161

62-
expect(result).toMatchObject({
63-
error: 'request_failed',
64-
message: 'Request failed: {"foo":"bar"}',
65-
type: 'unknown_error',
66-
});
62+
expect(result).toHaveProperty('type', StepType.LoginFailure);
63+
expect(result).toHaveProperty('payload', { foo: 'bar' });
6764
});
6865

6966
it('returns request_failed GenericError for SerializedError', () => {

packages/journey-client/src/lib/journey.utils.ts

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -55,35 +55,6 @@ export function createJourneyObject(
5555
}
5656
}
5757

58-
/**
59-
* Type guard that checks whether a value resembles a Step response.
60-
* Used to detect step-shaped error payloads that should be treated as journey steps.
61-
*
62-
* @param value - The value to check
63-
* @returns True if the value is an object containing at least one known Step key
64-
*/
65-
function isStepLike(value: unknown): boolean {
66-
return (
67-
typeof value === 'object' &&
68-
value !== null &&
69-
[
70-
'authId',
71-
'callbacks',
72-
'code',
73-
'description',
74-
'detail',
75-
'header',
76-
'ok',
77-
'realm',
78-
'reason',
79-
'stage',
80-
'status',
81-
'successUrl',
82-
'tokenId',
83-
].some((key) => key in value)
84-
);
85-
}
86-
8758
/**
8859
* Maps an RTK Query dispatch result to a JourneyResult.
8960
* Narrows RTK errors first; only calls createJourneyObject when data is confirmed present.
@@ -98,7 +69,8 @@ export function resolveJourneyResult(
9869
): JourneyResult {
9970
if (error && 'status' in error) {
10071
const stepData = error.data;
101-
if (isStepLike(stepData)) {
72+
// If error.data is an object, we treat it as login failure
73+
if (typeof stepData === 'object' && stepData !== null) {
10274
return createJourneyObject(stepData as Step);
10375
}
10476

0 commit comments

Comments
 (0)