I passed a slug that was not in database through url and it threw me this error which i don't know how to handle.
[![Error Message thrown by RTK Query]
Here is my getServerSideProps logic.
It seems like I found a solution but are there any other ways to do this in a performant way as I don't want to keep repeating it for every single request.
Related
I'm trying to fetch data from API on Server Side using async fetch() but now in the method, I'm trying to join a set object, that I'm calling it in the template and it isn't working.
Always giving me an error that required function is not a function.
Any idea on how to fix that?
I figured out the problem. The thing was that I wasn't using the right way to join a set. I was using
setObj.join("; ")
and this was working fine on the client-side.
But I think because of the different render engine on the server-side. It wasn't resolving.
Solved it using
[...setObj].join("; ")
This was a JavaScript mistake rather than Nuxt.
I'm new to this thing. Correct me if I'm wrong somewhere.
The issue:
On the server, I'm receiving my api_key parameter as api key (with space instead of underscore), how do I send it with underscore?
Code:
data = {
api_key: this.state.api_key
}
axios.post('/resource', data)
.then(response => { console.log(response) });
I'm using both React and axios (must use axios) on the frontend, and Rails on the backend.
Thanks
UPDATE
The rails action which first receives the parameters:
private
resource_params
ActiveModelSerializers::Deserialization.jsonapi_parse(params)
end
Axios serializes object params with JSON.stringify, which means the request is almost certainly being sent how you want (unless you are transforming it somehow). The issue is probably something on the Rails end. Looking at your resource_params method, I can see you are using ActiveModelSerializers's JSON API adapter. However, the request you are sending with Axios is not JSON API Compliant. You might try JSON.parse(params) instead or better yet, use Strong Params. Also you mentioned that you are using resource_params as a before action, but it doesn't look like you are assigning an instance variable there as one might expect. How are you handling that response? Are you calling that method directly in your action as well?
Anyway if that doesn't help I would be happy to continue our discussion in the chat.
After hours beating my head about this, I've found the culprit: Visual Studio Code
This is the output on VS Code:
And this is the output on linux terminal:
This is such a stupid issue but it never occurred to me that the bloody text editor would omit the underscores.
Trully #chris-g, this wasn't an issue with JSON or React, it was on the Rails side as #Xavier suspected, though the issue is unrelated to the lack of underscores themselves.
This is what I get for giving Microsoft some credit after so long.
I am stuck at this. I have an OracleDB where there is a table with some locations. I am calling an HTTP method via RESTful webservice to get my data. Now I want to make this smooth and use this method to get my data on the server only when something in OracleDB changes. I call it something like this:
HTTP.call("GET", "my_url", {data: "json"}, function (error, result) {
if (error) {
console.log(error);
} else {
console.log("Webservice success - data");
// parseJson(result);
}
});
This is the server code. I put data in a collection and then use it on the client. I want to achieve that this method is called only when something changes in DB. I checked Tracker.autorun function which can help me with this I think. But how can I achieve this is going to be called once on the server and not everytime? (something like bodyOnLoad function but on the server). If I am missing something really obvious please give me a link where I can read the life cycle, because I can't really find a proper one.
You might want to check this article
REST organizes these Requests in predictable ways, using HTTP operation types, or verbs, to contruct appropriate responses. Requests originate from the client, and the common HTTP verbs include GET, POST, PUT, DELETE
And consider using a WebSocket for such a task.
You can definitely refer above link to understand the requirement for REAL_TIME application. what you want is real time solution, where, user just connects to server only once and never asks for data, instead data is automatically provided when demanded.
You may also like to see here.
Above link gives you information on how to establish a robust and responsive relation between client and server.
I'm trying to run a query that retrieves a specific set of users from the User table and presents them to a given logged in user, using the Parse JS SDK.
At first I was running a query like:
(new Parse.Query(Parse.Object.extends("_User"))).containedIn("objectId", [/* list of user ids */]).find(/* success & error blocks */);
but then I learned the more correct way was:
(new Parse.Query(Parse.User)).containedIn("objectId", [/* list of user ids */]).find(/* success & error blocks */);
But even with this, I would get back an empty list. I double-checked the db and made sure the ids I was passing were in there, and they were. Just for the hell of it I tried:
(new Parse.Query(Parse.User)).find(/* success & error blocks */);
And I got back the user object corresponding to the current user. So it seems my User queries are only able to access the current user. I also noticed that when I tried running an equivalent query from the Parse API Console, I got the same results! Is this some sort of global setting, or am I doing something wrong? Thanks!
I believe you have to use CloudCode due to User Security Settings in Parse. Try shifting this to a cloud code function and include
Parse.Cloud.useMasterKey()
prior to the cloudcode function. This is a security 'feature' of Parse to ensure people can't edit and access other user profiles and information.
See Parse security site here:
https://parse.com/docs/js/guide#security-object-level-access-control
and more on use and considerations of implementing useMasterKey() and its persistence.
https://parse.com/docs/js/guide#security-implementing-business-logic-in-cloud-code
I would recommend not condensing all these calls into one line for the sake of saving lines. It sacrifices readability. Although, it's technically not wrong, and the docs even say the calls return a query so you can chain calls, so to each their own.
I don't see anything wrong with your call, though. How are you accessing the retrieved objects? What is the list of objectIds that you are passing into containedIn? We need a bit more of your code here, I think.
edit - I would say I'm 80% sure, without more information, that this is an ACL / CLP issue. Go to the dashboard, hit the _User class, press Security, and see what the read/write settings are.
Looks like a CLP issue to me. Maybe Find permission on your User class is disabled. Go to your User class, tap on security, switch to advance and then check whether the Find permission is ticked off or not.
I'm a little confused with how to support both server-side queries and client-side filtering with dstore, and am hoping for some guidance. My scenario:
I am communicating with an archive server, so I only have get and query requests, nothing that updates the data.
I want to perform both server-side queries and client-side filtering.
I'd like to cache the results so I'm not accessing the server for every fetch().
If I use a Request, filter() will pass its query parameters to the server, but the data isn't cached and I can't tell how to filter on the client side.
If I use a RequestMemory, filter() is applied to the local cache, and I can't tell how to specify parameters for the server.
All the pieces seem to be there with dstore, I just haven't figured out how to put them all together yet. Thanks for any help.
Looks like I figured it out. There were a couple issues with how I was using RequestMemory. The first was that I didn't realize RequestMemory invoked fetch() automatically. The second issue was that I used an object as the queryParam when it should have been an array.
To meet my requirements I created a new store that extended from Request and Cache, just like RequestMemory, but I did not call fetch() in the postscript() function. Then I could pass parameters to the server:
store.fetch({queryParams: ['key=value']}).then(function(data) {
console.log("fetch", data);
});
I could then 'freeze' the store by setting store.isValidFetchCache = true and subsequently perform client-side filters:
store.filter({type: 'xyz'}).fetch().then(function(data) {
console.log("filter", data);
});