Some how sequence or delay on server calls brings different behaviour. Code should explain this more clearly.
let editProfile = function (e) {
e.preventDefault();
let info = {};
info.username = $(".editProfile #usernameInput").val();
info.email = $(".editProfile #emailInput").val();
let picture = $(".editProfile #imageInput")[0].files[0];
if (picture) { <-|
Images.insert(picture); |Problem
} |
Meteor.call("editProfile", this, info); <-|
};
this works fine but when I try to change the sequence of these calls I get error in the console.
Meteor.call("editProfile", this, info); <-|
if (picture) { |Error is given
Images.insert(picture); |
} <-|
Error in browser:
Failed to load resource: the server responded with a status of 404 (Not Found)
Error: "Queue" failed [404] Not Found [404] [undefined], Error: failed [404] Not Found [404] [undefined]
at cfs_upload-http.js:351
at cfs_upload-http.js:77
at underscore.js:750
at XMLHttpRequest.xhr.onreadystatechange (cfs_upload-http.js:200)
If I try to do something like this: (no error is given)
Meteor.call("editProfile", this, info);
setTimeout(function () {
if (picture) {
Images.insert(picture);
}
},2000);
I would really like to know why this behaviour is affected by timeouts/sequence.
Related
I'm writing a vue project with WebSocket.I write WebSocket-Client's code in a module.I code like below:
//websocket.js
var graphqlWSClient = new WebSocket("ws://localhost:8000", "graphql-transport-ws")
function isOpened(){
return graphqlWSClient.readyState == 1
}
export function initialClient(){
graphqlWSClient.onopen = function (eve) {
graphqlWSClient.send(JSON.stringify({"type":"connection_init","payload":{}}))
}
}
//Heartbeat function to detect whether connenction working
export function testHeart(){
setInterval(()=>{
if(isClosed()){
graphqlWSClient = new WebSocket("ws://localhost:8000", "graphql-transport-ws")
graphqlWSClient.onopen = function(eve){ //!!!NOT WORK
console.log(eve)
console.log("state:",graphqlWSClient.readyState)
graphqlWSClient.send(JSON.stringify({"type":"connection_init","payload":{}}))
}
}
try {
graphqlWSClient.send(JSON.stringify({"type":"ping"}))
} catch (error) {
console.log(error)
}
},3000)
}
In the vue's component,I use it like below:
import * as graphqlSocket from '#/utils/websocket'
//In created():
graphqlSocket.initialClient()
graphqlSocket.testHeart()
In the function testHeart(),I expect it restarts the connection when connection is closed(whether server or client close it).But when I test it,the graphqlWSClient.onopen looks working instantly,not working until the connection is opened,as the console throw error:
state: 0
Uncaught DOMException: Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.
at graphqlWSClient.onopen
Does anyone can tell me why?😢😢😢
I have a React application that calls the Places API through Google's dedicated places library.
The library is imported as such:
<script defer src="https://maps.googleapis.com/maps/api/js?key=<API_KEY>&libraries=places&callback=initPlaces"></script>
The code above is inside /public, in index.html. The initPlaces callback, specified in the URL looks as such:
function initPlaces() {
console.log("Places initialized");
}
To make the actual request, the following code is used:
async function makeGapiRequest() {
const service = new window.google.maps.places.AutocompleteService();
const response = await service.getQueryPredictions({
input: "Verona"
});
console.log(res);
}
For testing purposes, the function is called when the document is clicked:
document.addEventListener("click", () => {
makeGapiRequest();
});
On every request, there is a response coming back. For instance, when the input has the value of Verona, the following response is received, and is only visible in the browser network tab:
{
predictions: [
{
description: "Verona, VR, Italy",
...
},
...
],
status: "OK"
}
Whenever maleGapiRequest is called, even though there is a visible response from the API, the response variable is undefined at the time of logging, and the following error is thrown in the console:
places_impl.js:31 Uncaught TypeError: c is not a function
at places_impl.js:31:207
at Tha.e [as l] (places_impl.js:25:320)
at Object.c [as _sfiq7u] (common.js:97:253)
at VM964 AutocompletionService.GetQueryPredictionsJson:1:28
This code is thrown from the Places library imported in /public/index.html.
Did anyone encounter this error before, or has an idea as to what is the problem? I would like it if the solution was available to me, not the library.
The problem was that I was calling the wrong method. Instead of getQueryPredictions call the getPlacePredictions method. It will return different results, but you can configure it to suite your needs.
Old code:
async function makeGapiRequest() {
const service = new window.google.maps.places.AutocompleteService();
const response = await service.getQueryPredictions({
input: "Verona"
});
console.log(res);
}
New code:
async function makeGapiRequest() {
const service = new window.google.maps.places.AutocompleteService();
const response = await service.getPlacePredictions({
input: "Verona",
types: ["(cities)"]
});
console.log(res);
}
In my node app, I'm trying to return a simple object and getting this error in my console:
Error generating response. TypeError: response.json is not a function
code in my messaging.js file :
module.exports = {
getConfig: function(res) {
getConfig(res);
}
};
function getConfig(response) {
response.json({
enabledForAll: false,
limit: 100
});
};
In main.js
const messaging = require("./modules/messaging.js");
Parse.Cloud.define("getConfig", messaging.getConfig);
Any advice? Thanks
A parse FunctionResponse only has two properties. success and error.
Additionally, the data portion of the define callback has two function inputs, FunctionRequest and FunctionResponse, so you may need something like function(req,res){ res.success();}
I have an error in the console every time I'm deleting an item (List) in my Meteor application.
The error in the console is:
domrange.js:337 Uncaught Error: Must be attached
Here is the function, I can't understand where come from this error:
Lists.js
Meteor.methods({
'lists.remove'(listId) {
check(listId, String);
const list = Lists.findOne(listId);
if (list.owner !== this.userId) {
throw new Meteor.Error('not-authorized');
}
Tasks.remove({"listId": listId});
Lists.remove(listId);
},
All is working properly in the application but do you know where this error can come from ?
Ps: I'm using Blaze if it can help
thanks
It seems I found the solution adding a Meteor.isServer or better if (!this.isSimulation) (#MasterAM solution):
'lists.remove'(listId) {
check(listId, String);
const list = Lists.findOne(listId);
if (list.owner !== this.userId) {
throw new Meteor.Error('not-authorized');
}
if (!this.isSimulation) {
Tasks.remove({"listId": listId});
Lists.remove(listId);
}
},
I edited the working code with the help of #MasterAM It'w working now! No Console error anymore.
This is a piece of an existing dojo based project
nps.makeRequest = function(args) {
//add some default params
return dojo.xhr("POST", args, true); // dojo/_base/Deferred
};
The issue is if the respose has an error message(text message) it is displayed properly.
if the response is say 404 and if there is a custom error page served , it will display the HTML source code of 404 page instead of interpreting it.
how to handle the error here?
You can either do
args = {
url: 'http://...',
error: function() { /* this handles error*/ }
};
nps.makeRequest(args);
Or you can use the deferred:
nps.makeRequest({url: 'foo'}).then(function() { /* this handles happy flow*/ }, function() { /* this handles error*/ });