All files / api/src/ai-providers/groq utils.ts

97.14% Statements 34/35
94.44% Branches 17/18
100% Functions 1/1
97.14% Lines 34/35

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 441x   1x   1x 3x 3x 3x 3x     3x 3x 1x 2x 1x 1x   3x 3x 1x 2x   3x 3x   3x   3x 3x 1x 2x   3x 3x 3x 3x 3x 3x 3x 3x 3x 3x  
import { generateErrorResponse } from '@api/utils/ai-provider';
import type { ErrorResponseBody } from '@shared/types/api/response/body';
import { AIProvider } from '@shared/types/constants';
 
export const groqErrorResponseTransform = (
  aiProviderResponseBody: Record<string, unknown>,
  aiProviderResponseStatus: number,
): ErrorResponseBody => {
  const error = aiProviderResponseBody.error;
 
  // Extract error details with proper type checking
  const message =
    typeof error === 'object' && error && 'message' in error
      ? String(error.message)
      : typeof error === 'string'
        ? error
        : 'Unknown error occurred';
 
  const type =
    typeof error === 'object' && error && 'type' in error
      ? String(error.type)
      : undefined;
 
  const param =
    typeof error === 'object' && error && 'param' in error
      ? String(error.param)
      : undefined;
 
  const code =
    typeof error === 'object' && error && 'code' in error
      ? String(error.code)
      : aiProviderResponseStatus.toString();
 
  return generateErrorResponse(
    {
      message,
      type,
      param,
      code,
    },
    AIProvider.GROQ,
  );
};