keco39
keco39
NNuxt
Created by keco39 on 7/25/2024 in #❓・help
NuxtUI: "aliases startsWith is not a function" after upgrade
Been searching for a while and finally found the "solution". It seems the order in which modules are set in NuxtConfig is important for when they're loaded. I put "@nuxt/ui" as the last one in the list and now it loads correctly. Came to that idea by reading about aliases and such... So when someone would encounter the same issue, that's the answer.
2 replies
NNuxt
Created by Kyllian on 2/11/2024 in #❓・help
$fetch catches error, but not able to read body
Didn't know that was a thing (now I have to find the type of that error :)). Sorry for the question (but maybe the answer can help others).
32 replies
NNuxt
Created by Kyllian on 2/11/2024 in #❓・help
$fetch catches error, but not able to read body
Just found this online...
console.error("Campaign Monitor error:", error.response._data);
console.error("Campaign Monitor error:", error.response._data);
32 replies
NNuxt
Created by Kyllian on 2/11/2024 in #❓・help
$fetch catches error, but not able to read body
{
"Code": -213,
"Message": "Please provide a consent to track value."
}
{
"Code": -213,
"Message": "Please provide a consent to track value."
}
32 replies
NNuxt
Created by Kyllian on 2/11/2024 in #❓・help
$fetch catches error, but not able to read body
And this is what I see in Postman (status is 400 Bad Request)...
32 replies
NNuxt
Created by Kyllian on 2/11/2024 in #❓・help
$fetch catches error, but not able to read body
Not really what I was hoping for 😦 This is what was returned (I put an extra try..catch in my page, calling my own API endpoint):
Campaign Monitor error in page: FetchError: [POST] "/api/newsletters/subscription?listid=...": 500 Campaign Monitor error: FetchError: [POST] "https://api.createsend.com/api/v3.3/subscribers/....json": 400 Bad Request
at async $fetch22 (ofetch.00501375.mjs:261:15)
at async subscribe (newsletters.vue:24:30)
at async updateSubscription (newsletters.vue:55:5)
Campaign Monitor error in page: FetchError: [POST] "/api/newsletters/subscription?listid=...": 500 Campaign Monitor error: FetchError: [POST] "https://api.createsend.com/api/v3.3/subscribers/....json": 400 Bad Request
at async $fetch22 (ofetch.00501375.mjs:261:15)
at async subscribe (newsletters.vue:24:30)
at async updateSubscription (newsletters.vue:55:5)
32 replies
NNuxt
Created by Kyllian on 2/11/2024 in #❓・help
$fetch catches error, but not able to read body
Sure 🙂 Gonna try to see if I get more details from the error itself...
32 replies
NNuxt
Created by Kyllian on 2/11/2024 in #❓・help
$fetch catches error, but not able to read body
Instead of the "Internal error", I would like to "personalize" it according to the error message within the 400 response.
32 replies
NNuxt
Created by Kyllian on 2/11/2024 in #❓・help
$fetch catches error, but not able to read body
try {
const body: CampaignMonitorSubscriptionRequest = { EmailAddress: payload.email, Name: payload.name, Resubscribe: true, ConsentToTrack: "Yes" };
const response: string = await $fetch(postUrl, { method: "POST", body: body, headers: { Authorization: `Basic ${authToken}` } });

if (import.meta.dev) {
// eslint-disable-next-line no-console
console.debug("Campaign Monitor POST subscription response", response);
}

return {
success: true,
email: response,
};
}
catch (error) {
// https://www.campaignmonitor.com/api/v3-3/subscribers/#adding-a-subscriber
console.error("Campaign Monitor error:", error);

return {
success: false,
message: "Internal error.",
};
}
try {
const body: CampaignMonitorSubscriptionRequest = { EmailAddress: payload.email, Name: payload.name, Resubscribe: true, ConsentToTrack: "Yes" };
const response: string = await $fetch(postUrl, { method: "POST", body: body, headers: { Authorization: `Basic ${authToken}` } });

if (import.meta.dev) {
// eslint-disable-next-line no-console
console.debug("Campaign Monitor POST subscription response", response);
}

return {
success: true,
email: response,
};
}
catch (error) {
// https://www.campaignmonitor.com/api/v3-3/subscribers/#adding-a-subscriber
console.error("Campaign Monitor error:", error);

return {
success: false,
message: "Internal error.",
};
}
32 replies
NNuxt
Created by Kyllian on 2/11/2024 in #❓・help
$fetch catches error, but not able to read body
This is the whole thing actually...
32 replies
NNuxt
Created by Kyllian on 2/11/2024 in #❓・help
$fetch catches error, but not able to read body
Or read err.data without the ignore option? Because TS also says it does not know .data and I don't really know of which type the error is.
32 replies
NNuxt
Created by Kyllian on 2/11/2024 in #❓・help
$fetch catches error, but not able to read body
I did do the try catch but the error object looks just like a string... Or can I pass "ignoreResponseError: true" as an option to $fetch (TS isn't recognizing it it seems...).
32 replies
NNuxt
Created by Kyllian on 2/11/2024 in #❓・help
$fetch catches error, but not able to read body
This answer means it's not possible to get the error object from a $fetch request (you have to use ofetch)? I was hoping I didn't have to install another package for that... My use case is the following: there is no up-to-date package for Campaign Monitor (for Nuxt/Vue/Node) so I created a couple of API endpoints to call CM myself (like this: const response: string = await $fetch(https://api.createsend.com/api/v3.3/subscribers/${listid}.json, { method: "POST", body: body, headers: { Authorization: Basic ${authToken} } });). When an error occurs, I only see "400 Bad Request" and a stacktrace but I'm missing the underlying reason (so I have to use tools like PostMan to check what the actual error is).
32 replies