AlokaiA
Alokai2y ago
42 replies
valerii.f

SDK error handling

Hello 👋

We have our custom integration, using REST API.

Endpoint example:

SDK folder:
export async function generateCustomerToken(props: LoginPayload) {
  try {
    const { data } = await client.post<LoginResponse>('generateCustomerToken', props);
    return data;
  } catch (error) {
    throw error
  }
}

API Client folder:
export const generateCustomerToken: Endpoints['generateCustomerToken'] = async (
  context,params
) => {
  try {
    const { config } = context;
    const { data } = await context.client.post<LoginResponse>(
      `${config.baseApi}/${config.apiVersion}/customer/login/token`,
      params,
      {
        headers: getHeaders(context),
      }
      );
      
      return data;
    } catch (error) {
      // error is AxiosError
      throw error.response.data;
    }
};



Using integration with Next.js application.

when calling this endpoint fails, getting eror:
SDKError: Request failed with status code 400
    at handleError (index.es.js:64:1)
    at Object.eval [as generateCustomerToken] (index.es.js:259:1)



What am I missing, how/where should we properly handle errors with integration ?

Thanks!
Was this page helpful?