DAS error [InternalAPIError: User already exists. Use another email.] { status: 'UNPROCESSABLE_ENTITY', body: { code: 'USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL', message: 'User already exists. Use another email.' }, headers: {}, statusCode: 422}
DAS error [InternalAPIError: User already exists. Use another email.] { status: 'UNPROCESSABLE_ENTITY', body: { code: 'USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL', message: 'User already exists. Use another email.' }, headers: {}, statusCode: 422}
Which makes me think that the error is of type
InternalAPIError
InternalAPIError
but that is not exposed. So when using TS I have to inspect the error:
function hasErrorCode(error: unknown): error is { body: { code: string } } { if (typeof error !== "object" || error === null) return false; const body = (error as { body?: unknown }).body; if (typeof body !== "object" || body === null) return false; const code = (body as { code?: unknown }).code; return typeof code === "string";}
function hasErrorCode(error: unknown): error is { body: { code: string } } { if (typeof error !== "object" || error === null) return false; const body = (error as { body?: unknown }).body; if (typeof body !== "object" || body === null) return false; const code = (body as { code?: unknown }).code; return typeof code === "string";}
Is there another way to handle this without having to have that utility function to satisfy TS?