Receiving 500 error from soundcloud api only on my ubuntu server - javascript

I am running a node application which uses the request lib to access playlist information from soundcloud. On my local machine, this works without a hitch, but on my ubuntu server it does not. What's more, it was working before and has only recently stopped working. All other HTTP requests leaving my server are executing just fine.
I have heard that this could be due to request limits, but I have specifically constructed my app in such a way that it is only calling to the API once every 5 minutes which is well-below the 15,000 request limit per 24 hours. Additionally, I should probably be receiving a 429 error code if that were the case, as per soundcloud docs
https://developers.soundcloud.com/docs/api/rate-limits#play-requests
The 500 error i'm getting is incredibly non-specific:
<html><body><h1>500 Server Error</h1>
An internal server error occured.
</body></html>
Here is what my request looks like:
https://api.soundcloud.com/users/<user_id>/tracks?client_id=<my_client_id>&offset=1&order=created_at&created_at={from: 2016/02/22 05:45:31 +0000}
where both the user_id and the my_client_id are correctly populated. If i take the same URL and print it into my web browser ur a wget from my local machine, i have no problems.

This seems to be resolved by Soundcloud internally. Not sure what was causing it.

Related

How do I fix a 429 API request error in javascript?

I am working with an API (I am noob at API's) and after some time I got this error "Request was throttled. Expected available in 82248 seconds." This is a really important project I am working on and I didn't know there was a possibility for this to happen (lesson learned ). I can't wait that long to make a request again, is there another way to regain access to the API? Maybe activating a VPN or something like that? Thank you in advance for your response.
HTTP error 429 means that sent too many requests within a minute to the server, and the server assumes you either do not know what you are doing and/or doing a DOS attack. Servers usually do this to make sure it can continue to work with other clients. See more details here
To solve your problem, just stop sending request on the server for couple of seconds (may be a minute depending how much you sent in the past minute. And it will work again. Rate limit may be implemented on the server globally, on a specific endpoint, or on a resource - check the API documentation for more details, here is a facebook example.

Can't make a fetch in IE9 once page is loaded

I have a site that is running in Node and using express for the server. I also have an API on a different server I need to hit. Everything works fine except in IE9. The issue is when ever i try to hit my API once i have the page loaded it breaks.
For example on the home page i have a search form where each step makes an API fetch and once I try to make my first fetch i get this error
"Unhanded promise rejectionError: Access Denied"
It seems like it has to do with a CORS issue since IE9 didnt have CORS and the era of the error message. Also when I make the fetched server side I have no issue, its just when the client tries to perform them.
Has anyone had an issue like this and if so how did you fix it?
Currently I am trying this but it hasnt worked yet:
First I changed my api host address to the current sites address with /api at the end.
apiHost: process.env.API_HOST || 'http://127.0.0.1:3000/api'
Then in my express server is run this:
app.use(modRewrite([`^/api/(.*)$ http://api.mysite.dev:8080/$1 [P]`]));
I was hoping to avoid making a fetch cross address with this but no luck as of yet.
Any help would be much appreciated
thanks!
To solve this problem I changed my host file for my machine to use mysite.dev for the 127.0.0.1 IP. Then went to mysite.dev rather than 127.0.0.1 when testing my site. Then did what I did above to get it to work

High responsetime from Web API after 5 min inactivity

I have a weird problem in a preproduction environment.
I have a website which performs some operations on a Web Api hosted on another server.
Usually it takes under a second to make a specific post request, but after 5 minutes of inactivity the same post request will take 10-30 seconds. (According to google chrome network tab)
The mentioned post request is not the first request in a list of requests performed.
The request is done using Ajax.
I have run SQL profiler to see if the database queries were running slow, but these are all performing fine, and it looks like the POST request is just returning with a delay.
Do you guys have any idea why this is happening?
A very likely cause is compiling at the database level. The first time you run a query with most database engines, the sql has to be compiled and an execution plan developed. This is then cached for a while. When it is no longer cached, it has to be done again. The longer your sql string, the longer it takes to compile.
The solution is to use a stored procedure. Once it runs once it stays compiled and the execution plan is always available.
Problem solved!
The problem was that an email was sent using SMTPClient in the request.
In a web application the smtp client is not async and therefore it had to be sent before the POST request returned.
Making it async using the reply from TheCodeKing in this question:
How do I avoid a delay when sending email from my application?
solved the problem!

socket.io referring to localhost despite being set as a specfic IP

I'm trying to use web sockets to connect from a Google Chrome browser on my phone to a server running node.js and socket.io.
Using the remote debugging tool in Google Chrome I get this error in the console
Failed to load resource http://localhost/socket.io/1/?t=1368744562638
This happens despite me specifying my internal LAN IP in code for the client like so:
var socket = io.connect('http://192.168.1.3');
Furthermore it seems like the first heartbeat request makes it but starts to fail after that.
The code runs as expected when running the client on the server.
I am of course a idiot. I had another javascript file that had not been updated to connect to the specific IP I had set and was still set to "localhost".
After updating the host that socket.io should connect to in that javascript file everything is now running smoothly :)

SSE Uncaught Error: SECURITY_ERR: DOM Exception 18 with a server that provides Server Sent Events (SSE)

I am trying to connect browsers with a server that provides Server Sent Events (SSE). This server has a different domain than the original one. For example if you call http://d1.example.com/page this page will try to connect to an SSE channel on http://d2.example.com/subscribe. Trying to do that will prompt the following error:
Uncaught Error: SECURITY_ERR: DOM Exception 18
on the line:
var source = new EventSource("http://d2.example.com/subscribe")
How can I fix that?
Update (Solutions that I have tried out):
1- CORS
I tried CORS by adding Access-Control-Allow-Origin:* to the headers of my web service d2.example.com. It did not solve EventSource problem, even though $.get("http://d2.example.com") calls from d1.example.com pages are working fine now! I thought SSE works on normal HTTP requests, so why is it not working on Chrome?
2- Redirect
I am using httpd server, so I created a redirect rule in d1.example.com virtual host that passes SSE requests to d2.example.com. It worked perfectly with Firefox. Chrome on the other hand did not prompt any error and did not connect to the SSE server either. It looks like it dumped the whole EventSource command. It looks like this solution will never work, so lets move on...
3- Reverse proxy
Both browsers connected on d1.example.com/subscribe which is basically connecting to d2.example.com through reverse proxy. But on_close event is never caught, even if the browser is closed. Which makes sense since the d2 server is now making the channel with the proxy server. How can I forward the on_close event from proxy server to d2?
Is there any different ways that could make this work?
The odds are high this is an issue of cross-origin resource sharing, which you must enable on the relevant domains.
http://enable-cors.org/
As the MDN says:
Note: Although it's not yet part of the standard, EventSource supports CORS in Firefox 11 and later. This is expected to become standard soon.

Categories