uncaught exception: INVALID_TOKEN | (intermediate value).forEach is not a function with AJAX response(JSON format) - json

I am getting error uncaught exception: INVALID_TOKEN (intermediate value).forEach is not a function
My code is:
$('#start')
.on('click', function() {
$.getJSON('/twillio-new/token.php', {
name: $('#my-name')
.val(),
identity: $('#my-identity')
.val()
}, function(data) {
// Create the endpoint, and then initialize the main calling app
var endpoint = new Twilio.Endpoint(data.token);
$('#startDiv')
.hide();
$('#callDiv')
.show();
init(endpoint);
});
});
JSON Response:
{"name":"cool
room","identity":"test","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImN0eSI6InR3aWxpby1mcGE7dj0xIn0.eyJqdGkiOiJlMWE3NTI4YzYyMzdiMGE0MmZlYTc0NDk2MjRlOTFiNC0xNTA3MjEwNjQyIiwiaXNzIjoiZTFhNzUyOGM2MjM3YjBhNDJmZWE3NDQ5NjI0ZTkxYjQiLCJzdWIiOiJBQzVlMTVhMDg5NjVkNWRjM2ZkOWI3YmNiOGMyM2FhMjgxIiwiZXhwIjoxNTA3MjE0MjQyLCJncmFudHMiOnsiaWRlbnRpdHkiOiJ0ZXN0IiwidmlkZW8iOnsicm9vbSI6IiRuYW1lIn19fQ.pvfGEoVripcjq588p8l3QixuVJ4sHBjMdmWa8tspTtY"}
I am generating and getting access token for Twilio Video calling api using this. Please let me know what is wrong with this code?

Which SDK do you have installed? I have seen this error when the code being used was for the incorrect SDK. Looks like the code you are using is for the version 5. Do you have version 5 installed? There have been numerous version based issues with Twilio

Related

Caught exception: TypeError: listener is not a function while publish redis client using node v16.16.0, redis-cli 7.0.0 & "redis": "^4.2.0",

When using node v16.16.0, redis-cli 7.0.0 & "redis": "^4.2.0"
getting such exeption below:
Caught exception: TypeError: listener is not a function Exception
origin: uncaughtException[2022-07-18T07:39:30.386Z] process.on
uncaughtException ERRORCODE 105199 TypeError: listener is not a
function
at Function._RedisCommandsQueue_emitPubSubMessage (/mnt/c/Projects/konnectcore/app/sse/sse/node_modules/#redis/client/dist/lib/client/commands-queue.js:241:9)
at RedisCommandsQueue._RedisCommandsQueue_handlePubSubReply (/mnt/c/Projects/konnectcore/app/sse/sse/node_modules/#redis/client/dist/lib/client/commands-queue.js:283:100)
It's working fine while using node redis "redis": "^2.8.0".
I had a similar issue where I was using probably some old way of subscribing and receiving the messages. Something like this:
sub.on('message', (channel, message) => {
redisClient.hSet('values', message, someFunction);
});
sub.subscribe('channel');
I hope you are using the right way of publishing and subscribing to a channel in redis client. Here is one example from their documentation:
// This is how you create the client
import { createClient } from 'redis';
const client = createClient();
// This is the subscriber part
const subscriber = client.duplicate();
await subscriber.connect();
await subscriber.subscribe('channel', (message) => {
console.log(message); // 'message'
});
// This is an example of how to publish a message to the same channel
await publisher.publish('channel', 'message');
Here is the link if you would like to see some more details about publishing and subscribing of the messages using node-redis client: https://github.com/redis/node-redis#pubsub

VSCode JSON language server unhandled method

I posted this last week and have made progress since, where I've discovered the packages that VSCode's JSON support is delivered via extensions:
https://github.com/vscode-langservers/vscode-json-languageserver
https://github.com/Microsoft/vscode-json-languageservice
and all the rest. I'm trying to reuse this in an Electron (NodeJS) app. I'm able to fork a process starting the language server and initialize it:
lspProcess = child_process.fork("node_modules/vscode-json-languageserver/out/jsonServerMain.js", [ "--node-ipc" ]);
function initialize() {
send("initialize", {
rootPath: process.cwd(),
processId: process.pid,
capabilities: {
textDocument: true
}
});
}
lspProcess.on('message', function (json) {
console.log(json);
});
and I see that console.log firing and showing it seems to be up correctly.
My thoughts are that I just want to send a textDocument/didChange event as per the LSP:
send('textDocument/didChange', {
textDocument: TextDocument.create('foo://bar/file.json', 'json', 0, JSON.stringify(data))
});
where data is a JSON object representing a file.
When I send that message and other attempts at it I get
error: {code: -32601, message: "Unhandled method textDocument/didChange"}
id: 2
jsonrpc: "2.0"
Any idea what I'm doing wrong here? My main goal is to allow edits through my Electron app and then send the updated JSON to the language server to get schema validation done.
EDIT: I'm even seeing unhandled method initialized when I implement connection.onInitialized() in the jsonServerMain.js.
EDIT2: Update, I figured out where I was going wrong with some of this. initialized and textDocument/didChange are notifications, not requests.
EDIT2: Update, I figured out where I was going wrong with some of this. According to the LSP, initialized and textDocument/didChange are notifications, not requests. Requests have an id field that notifications don't, so when sending a notification, remove the ID field.

Google Maps Javascript API: TypeError: response.data[0].geometry.location.lat is not a function

I successfully get an answer from the Google Map Javascript Api and try to access the values of the google.maps.GeocoderResult to extract the latitude and longitude from the GeocoderGeometry / LatLng
I implemented response.data[0].geometry.location.lat(), following the TSD definition, which lead, while debugging in Chrome, to the error:
TypeError: response.data[0].geometry.location.lat is not a function
Having a look at the object in the debugger, show effectively that no method lat() or lng() aren't supported.
I could access to response.data[0].geometry.location.lat to successfully get the value in the debugger, but then my code isn't Typescript conform anymore.
Of course I could cast the result but still would like to understand the reason. Furthermore maybe someone has got an explanation and proposition of solution?
Best regards
For the record, the typescript definition:
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/0e139d5d4681b71d53a30408efcc64b79eed6354/googlemaps/google.maps.d.ts
Update with chrome debug info:
response.data[0].geometry.location.lat() => <not available>
response.data[0].geometry.location.lat: 47.37793800000001
response.data[0].geometry.location: Object
lat: 47.37793800000001
lng: 8.5401898
response.data[0].geometry: Object
location:Object
lat:47.377
lng: 8.5401898
stacktrace of the error:
TypeError: response.data[0].geometry.location.lat is not a function
at interestsParamsCtrl.js:61
at processQueue (ionic.bundle.js:29127)
at ionic.bundle.js:29143
at Scope.$eval (ionic.bundle.js:30395)
at Scope.$digest (ionic.bundle.js:30211)
at Scope.$apply (ionic.bundle.js:30503)
at done (ionic.bundle.js:24824)
at completeRequest (ionic.bundle.js:25022)
at XMLHttpRequest.requestLoaded (ionic.bundle.js:24963)
Update 2: To query the API I do a GET and let the response be parsed
search(searchLocationTerm:string):ng.IPromise<{}> {
var deferred = this.$q.defer();
this.$http.get(Resources.Constants.Default.GOOGLE.API.URL,
{
params: {
address: searchLocationTerm,
key: Resources.Constants.Default.GOOGLE.API.KEY
}
})
.success((response:Communication.IGeocoder) => {
deferred.resolve(response);
}).error((response:Communication.IGeocoder) => {
deferred.reject(response);
});
return deferred.promise;
};
Where IGeocoder is
export interface IGeocoder {
results:google.maps.GeocoderResult[];
status:google.maps.GeocoderStatus;
}
You are sending a web service request via AJAX. Please note that response of web service Geocoding API is a JSON object as specified in the documentation:
https://developers.google.com/maps/documentation/geocoding/intro?hl=en#GeocodingResponses
You should use a client side geocoding service instead to get an object compliant with definitions in google.maps.d.ts
Look at this example and client-side geocoder service documentation.

Cordova error when using angular to get remote json

I develop a little mobile app with cordova + onsen ui platform, i develop on a macbook pro, all things works perfectly but when i try to get remote json i get following error :
Uncaught Error: Module org.apache.cordova.file.resolveLocalFileSystemURI does not exist.
I search on google but not found similar issue, anyone can help me please?
Thank you.
Below is latest detail :
I deleted all angular json call and "Uncaught Error: Module org.apache.cordova.file.requestFileSystem does not exist." remain, so i think it's not an angular problem but cordova issue
Thanks all for your question, this is my code to get json from angular :
Note : i use onsen UI framework for the UI
ons.ready(function(){
myapp.controller("PostsCtrl", function($scope, $http) {
$http.get('http://www.e-sysoft.fr/myicc/?get=events').
success(function(data, status, headers, config) {
$scope.posts = data;
alert(data)
}).
error(function(data, status, headers, config) {
// log error
});
});
})
When i run this code nothing happens could you help me?

Determining the location of a JSON parse error

I am creating a web application that allows a user to load data in JSON format. I am currently using the following function to read JSON files that I have saved on my local disk:
function retrieveJSON(url, callback)
{
// this is needed because FireFox tries to parse files as XML
$.ajaxSetup({ mimeType: "text/plain" });
// send out an AJAX request and return the result
$.getJSON(url, function(response) {
console.log("Data acquired successfully");
callback(response);
}).error(function(jqXHR, textStatus, errorThrown) {
console.log("Error...\n" + textStatus + "\n" + errorThrown);
});
}
This works perfectly for well-formed JSON data. However, for malformed data, the console log displays the following:
Error...
parsererror
SyntaxError: JSON.parse: unexpected character
This is almost entirely unhelpful because it does not tell me what the unexpected character is or what line number it can be found on. I could use a JSON validator to correct the file on my local disk, but this is not an option when the page is loading files from remote URLs on the web.
How can I obtain the location of any error? I would like to obtain the token if possible, but I need to obtain the line number at minimum. There is a project requirement to display an excerpt of the JSON code to the user and highlight the line where any error occurred.
I am currently using jQuery, but jQuery is not a project requirement, so if another API or JSON parser provides this functionality, I could use that instead.
Yeah, life with deadlines is never easy :).
This might help you out, after couple of hours googling around, I've found jsonlint on Git Hub. It looks promising, it includes a shell script that could be used on server side, and there is a browser JavaScript version of it that seems to be exactly what you were looking for.
Hope that this will help You.
i agree that life with deadlines is hard.
i'm incredibly happy that i don't have to live with deadlines, i'm my own boss.
so in search of a better solution to this problem, i came up with the following :
...
readConfig : function () {
jQuery.ajax({
type : 'GET',
url : 'config.json',
success : function (data, ts, xhr) {
var d = JSON.parse(data);
},
error : function (xhr, ajaxOptions, thrownError) {
if (typeof thrownError.message=='string') {
// ./config.json contains invalid data.
var
text = xhr.responseText,
pos = parseInt(thrownError.message.match(/position (\d+)/)[1]),
html = text.substr(0,pos)+'<span style="color:red;font-weight:bold;">__'+text.substr(pos,1)+'__</span>'+text.substr(pos+1, text.length-pos-1);
cm.install.displayErrorMsg('Could not read ./config.json :(<br/>'+thrownError+'<br/>'+html);
} else {
cm.install.displayErrorMsg('Error retrieving ./config.json<br/>HTTP error code : '+xhr.status);
};
}
});
},
...