valerii.f
valerii.f
AAlokai
Created by valerii.f on 1/15/2024 in #🙋|general-help
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
}
}
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;
}
};
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)
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!
43 replies
AAlokai
Created by valerii.f on 12/20/2023 in #🙋|general-help
Deploy Vuestorefront with Docker
Hi community, I am trying to understand the deployment part. So I have a vuestorefron application running React/Next.js I have a vuestorefront integration with (custom) When I connected React/Next.js with integration - locally, the integration server is running on the http://localhost:8181/ when in React/Next.js app I call sdk.customIntegration.generateCustomerToken(payload) - I can see in Chrome Devtools that it does POST request to an endpoint http://localhost:8181/customIntegration/generateCustomerToken So now I am ready to deploy this application LIVE, when I deploy React/Next.js application - it can be accessed on some specific domain let's say mysite.com when I deploy a middleware application - I should also expose it to the world on a specific domain let's say api.mysite.com I can't understand what should I configure in the React/Next.js application during build time, so that when the application calls SDK sdk.customIntegration.generateCustomerToken(payload) - it does POST request to http://api.mysite.com/customIntegration/generateCustomerToken Could you please help me with that ? Or maybe I am doing something wrong ? Thank you!
6 replies
AAlokai
Created by valerii.f on 11/20/2023 in #🙋|general-help
Problems using Custom Integration
Hello! I am writing custom integration using boilerplate npx @vue-storefront/cli create integration everything configured as per documentation, added endpoints - and it works fine with playground 🙂 And now I want to use it to connect to some demo application based on https://github.com/vuestorefront/storefront-next13-boilerplate/tree/develop And i need help here, it seems I am missing something, which doesn't let me start the middleware. Here is what I did so far. I built the middleware sdk: inside integration application -> packages/sdk -> run yarn build as a result I got the lib folder, which I copy into my Next.js application In the Next.js application I updated middleware.config.js with configuration and location: '@vue-storefront/integration-boilerplate-api/server' -> which looks weird to me, but that is another question. when trying to run middleware application getting error:
ℹ Middleware starting....
ℹ Loading integrations...
ℹ - Loading: nochannelApi @vue-storefront/integration-boilerplate-api/server

ERROR Cannot find module '@vue-storefront/integration-boilerplate-api/server'
Require stack:
- /vsf-ui/integration/node_modules/@vue-storefront/middleware/lib/index.cjs.js
- /vsf-ui/integration/middleware.js

Require stack:
- node_modules/@vue-storefront/middleware/lib/index.cjs.js
- middleware.js
ℹ Middleware starting....
ℹ Loading integrations...
ℹ - Loading: nochannelApi @vue-storefront/integration-boilerplate-api/server

ERROR Cannot find module '@vue-storefront/integration-boilerplate-api/server'
Require stack:
- /vsf-ui/integration/node_modules/@vue-storefront/middleware/lib/index.cjs.js
- /vsf-ui/integration/middleware.js

Require stack:
- node_modules/@vue-storefront/middleware/lib/index.cjs.js
- middleware.js
Could you please help me to understand what exactly am I doing wrong ? 🥹 🙏
9 replies