nazirov91 / ra-strapi-rest

React Admin data provider for Strapi.js
125 stars 40 forks source link

Internal Server Error #10

Closed ghazanfar23 closed 4 years ago

ghazanfar23 commented 4 years ago

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

ghazanfar23 commented 4 years ago

and this is the error I am getting in the console: Warning: Missing translation for key: "Not Found"

ghazanfar23 commented 4 years ago

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.

nazirov91 commented 4 years ago

Hi @ghazanfar23, sorry you are having that issue. What version of Strapi are you using?

nazirov91 commented 4 years ago

@ghazanfar23

  1. If the issue was in filtering and sorting you would not be getting a 500 error
  2. You need to override the 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

  1. Warning: Missing translation for key: "Not Found" - This warning just means that you do not have i18n translation for "Not Found" message. You can easily fix this by reading this page

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. :)