Closed ghazanfar23 closed 4 years ago
and this is the error I am getting in the console: Warning: Missing translation for key: "Not Found"
On network this is the link with issues: http://localhost:1338/seller-subscriptions?_end=10&_order=ASC&_sort=id&_start=0 and error: {statusCode: 500, error: "Internal Server Error", message: "An internal server error occurred"}
I can easily access my endpoint from http://localhost:1338/seller-subscriptions. Apparently issue is in sorting and filtering.
Hi @ghazanfar23, sorry you are having that issue. What version of Strapi are you using?
@ghazanfar23
find
method for seller-subscriptions in /api/seller-subscription/contorller/seller-subscription.js
. When you do that you have to reference the strapi service seller-subscription.js
. Since you probably already know you cannot be using hyphen while referencing JS objects. Instead you should be using key notation:// INCORRECT
ctx.set("Content-Range", await strapi.services.seller-subscriptions.count());
// CORRECT
ctx.set("Content-Range", await strapi.services["seller-subscriptions"].count());
So you should have the following in your /api/seller-subscription/contorller/seller-subscription.js
// /api/seller-subscription/contorller/seller-subscription.js
"use strict";
const { sanitizeEntity } = require("strapi-utils");
// prettier-ignore
module.exports = {
async find(ctx) {
let entities;
ctx.set("Content-Range", await strapi.services["seller-subscriptions"].count());
if (ctx.query._q) {
entities = await strapi.services["seller-subscriptions"].search(ctx.query);
} else {
entities = await strapi.services["seller-subscriptions"].find(ctx.query);
}
return entities.map(entity =>
sanitizeEntity(entity, { model: strapi.models["seller-subscriptions"] })
);
}
};
Even better option is to rename your seller-subscription to something without a hyphen
Since I have not received an answer from you for my previous question, I am closing this issue.
Please let me know if you are still facing this problem. :)
I have a find permission on my strapi model for public, I did go through all the steps for strapi, added the content-range and replaced the cors with provided code. I also imported the strapi-provider file in App.js and passed the URL both localhost:1338 and http://localhost:1338. My endpoint is seller-subscriptions and I passed in the Resource but I got the "An internal server error occurred". Thanks