Location query in Overpass turbo - javascript

I have just learned about the overpass turbo service and its ability for querying data. I have tried the following query and it works fine:
[out:json][timeout:25];
(
node["highway"]({{bbox}});
);
out body;
But when I replace the bbox with a name of city which according to the wiki page of overpass it should be like below, the code gives an error. Would be glad to know what is the problem with the second code?
[out:json][timeout:25];
(
node["highway"]({{geocodeId: Vienna}});
);
out body;
error message:
An error occured during the execution of the overpass query! This is
what overpass API returned: Error: line 3: parse error: Unknown query
clause Error: line 3: parse error: ')' expected - 'node' found. Error:
line 4: parse error: Unknown type ")" Error: line 4: parse error: An
empty query is not allowed Error: line 4: parse error: Unknown type
";" Error: line 5: parse error: An empty query is not allowed

As you want to query nodes in a certain area, you need to use the following syntax for overpass turbo:
[out:json][timeout:25];
{{geocodeArea:Vienna}}->.searchArea;
node["highway"](area.searchArea);
out body;

Related

Trying to call send function in web3 and it returns an error => Uncaught (in promise) Error: Returned error: unknown account

I am trying to call a method of smart contract which is a write method
const temp = await goin_contract.methods
.increaseAllowance("0xEd61D93121D0b8435f9D2AaCB7dea0A3D067c4E2", stakeValue)
.send({ from: account });
However whenever I call this method it returns this error
*Uncaught (in promise) Error: Returned error: unknown account
at Object.ErrorResponse (errors.js:28:1)
at index.js:302:1
at XMLHttpRequest.request.onreadystatechange*
Read methods of smart-contract are working perfectly.
I have read some articles on how to solve this error but cant find a definite solution. Any help will be appreciated.
You have to use Metamask provider instead of node URL const web3 = new Web3(window.ethereum);

"Uncaught SyntaxError: Unexpected token l in JSON at position 0", but still works, why?

First time using websockets with Go and getting a weird error that doesn't break the program, and still continue as if it was not a problem. The client is a ReactJS single page application.
JS Client:
const socket = new WebSocket("ws://localhost:5000/ws");
setConnection(socket);
socket.onmessage = (e) => {
const message = JSON.parse(e.data)
console.log("message:", message)
switch (message.Command) {
case "loginResult":
if (message.Result) {
console.log("login worked");
}else{
console.log("login did not work");
}
break;
}
}
Snippet of Go it is getting JSON from:
result := ws.LoginResult{
BaseMessage: ws.BaseMessage{
Command: "loginResult",
},
Result: false,
}
b, err := json.Marshal(result)
if err != nil {
fmt.Println(err)
return
}
if err = conn.WriteMessage(msgType, b); err != nil {
return
}
And the output:
in here
WebsocketProvider.tsx:20 message: {Command: 'loginResult', Result: false}
WebsocketProvider.tsx:27 login did not work
VM3502:1 Uncaught SyntaxError: Unexpected token l in JSON at position 0
at JSON.parse (<anonymous>)
at WebSocket.socket.onmessage (WebsocketProvider.tsx:19)
socket.onmessage # WebsocketProvider.tsx:19
Anyone have any idea why this is the case?
Solution was found:
It was to do with the migration of code and that a left over line was making a call that was ignored, hence where it made no difference to the execution. Nothing to do with the JSON format being difference since this was automatically generate by Go libraries.
the function you have written for onmessage will be run every time a valid websocket message has been received.
According to the debug log you have posted the bit that worked was when you did receive valid JSON from the server and the function ran to completion as evidenced by this line:
WebsocketProvider.tsx:27 login did not work
Mark the line number.
After this you get:
VM3502:1 Uncaught SyntaxError: Unexpected token l in JSON at position 0
at JSON.parse (<anonymous>)
at WebSocket.socket.onmessage (WebsocketProvider.tsx:19)
socket.onmessage # WebsocketProvider.tsx:19
mark the line number :19
This is the line with your JSON.parse.
My guess would be that this is a new invalid json message and it did indeed panic here and the rest of the function did not run - the bit that ran was a previous message with valid json.
As for why it failed - put in a console.log before your JSON.parse as suggested by #emptyhua to see what exactly you are receiving.

Script error in MDN web extension example

I am trying to run the MDB example extension at https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Your_second_WebExtension and it always fails with the message:
Failed to execute beastify content script unexpected token: ':'
The other message in the console says. scriptElement:88:13
I thought the error message comes from the : in the line but even removing it still gives the message, so there must be something passed in the string error.message that is causing the error.
The whole project is at https://github.com/mdn/webextensions-examples/tree/master/beastify and the error is from choose_beast.js line 88.
From what I see the ${error.message} contains some executable string that has a syntax error.
function reportExecuteScriptError(error) {
document.querySelector("#popup-content").classList.add("hidden");
document.querySelector("#error-content").classList.remove("hidden");
console.error(`Failed to execute beastify content script: ${error.message}`);
}

JSONP error: Uncaught SyntaxError: Unexpected token :

I am trying to get a json encoded object from here but I keep on receiving the following error "Uncaught Syntax Error: Unexpected token : ". I was wondering what is causing this error and what I could do to fix it. Thanks to anyone who can help. Here's my code.
<script>
function mycallback(answer){
var stuff = JSON.parse(answer);
alert(stuff);
console.log(stuff);
}
</script>
<script src="http://www.wcischeduleapp.com/app/get.php?callback=mycallback"></script>
The way JSONP works is that answer is already an object, not a JSON string any more.
So just console.log(answer); will work just fine.

Yummly API " Uncaught SyntaxError: Unexpected token : "

I am trying to request data from the Yummly API with the following call
$http.jsonp('http://api.yummly.com/v1/api/recipes?_app_id='
+ $scope.apiId
+ '&_app_key='
+ $scope.apiKey
+ '&allowedAllergy[]=396^Dairy-Free'
+ '/?callback=JSON_CALLBACK' ).success(function(data) {
console.log(data);
}).error(function(error) {
});
And I keep getting this error saying " Uncaught SyntaxError: Unexpected token : " and when I click it takes me to the response. It is also not logging the data in the console.
The sever is returning JSON - not JSONP. This in turns causes the exception when the JSON text is executed in the hosting <script> context.
Running the following code in the console will generate the same error because {..} is in a Statement context:
{"foo": "bar"}
On the other hand, a valid JSONP response should look like this (which is valid syntax because {..} is in an Expression context):
JSON_CALLBACK({"foo": "bar"})

Categories