DrKain/audd.io

Unexpected token < in JSON at position 0

Zucovsky opened this issue · 10 comments

Hi, i have this errors

FetchError: request to https://api.audd.io/ failed, reason: read ECONNRESE
T                                                                         
    at ClientRequest.<anonymous> (/root/petya/node_modules/node-fetch/lib/
index.js:1461:11)                                                         
    at ClientRequest.emit (node:events:369:20)                            
    at TLSSocket.socketErrorListener (node:_http_client:462:9)            
    at TLSSocket.emit (node:events:369:20)                                
    at emitErrorNT (node:internal/streams/destroy:188:8)                  
    at emitErrorCloseNT (node:internal/streams/destroy:153:3)             
    at processTicksAndRejections (node:internal/process/task_queues:81:21)
 {                                                                        
  type: 'system',                                                         
  errno: 'ECONNRESET',                                                    
  code: 'ECONNRESET'                                                      
}                                                                         
FetchError: invalid json response body at https://api.audd.io/ reason: Une
xpected token < in JSON at position 0                                     
    at /root/petya/node_modules/node-fetch/lib/index.js:272:32            
    at processTicksAndRejections (node:internal/process/task_queues:94:5) 
{                                                                         
  type: 'invalid-json'

What package & node version?
Please provide some code to show exactly how you were using the package

2.0.0 package
15.12.0 node

const { Audd } = require('audd.io')

audd.fromFile(track_name).then((response) => {...}

Update to the latest version and let me know if the problem persists. If the api isn't returning JSON then it's possible the API was down at the time

Now I have this problem

FetchError: request to https://api.audd.io/ failed, reason: read ECONNRESE
T                                                                         
    at ClientRequest.<anonymous> (/root/petya/node_modules/node-fetch/lib/
index.js:1461:11)                                                         
    at ClientRequest.emit (node:events:369:20)                            
    at TLSSocket.socketErrorListener (node:_http_client:462:9)            
    at TLSSocket.emit (node:events:369:20)                                
    at emitErrorNT (node:internal/streams/destroy:188:8)                  
    at emitErrorCloseNT (node:internal/streams/destroy:153:3)             
    at processTicksAndRejections (node:internal/process/task_queues:81:21)
 {                                                                        
  type: 'system',                                                         
  errno: 'ECONNRESET',                                                    
  code: 'ECONNRESET'                                                      
}

Are you able to to connect to https://api.audd.io/ in your browser?
It looks to be an issue with your connection, not this package

3.0.1 version has a bug

/root/petya/bot.js:59                                                     
    audd.recognize.fromFile(track_name).then((response) => {              
                   ^                                                      
                                                                          
TypeError: audd.recognize.fromFile is not a function                      
    at find_track (/root/petya/bot.js:59:20)                              
    at /root/petya/bot.js:51:13

@3.0.1 :/

3.0.1

It's not fixed :(

FetchError: invalid json response body at https://api.audd.io/ reason: Unexpected token < in JSON at position 0
    at /root/petya/node_modules/node-fetch/lib/index.js:272:32
    at processTicksAndRejections (node:internal/process/task_queues:94:5) {
  type: 'invalid-json'
}

This isn't really something I can fix. If the API is not returning valid JSON then it's an issue with https://audd.io/, not this package.

Considering Audd.io is a paid service, I would suggest you log the response (the document body) when this error occurs next and report it to Audd.io's support team. I would do this myself but I've been unable to reproduce the error with extensive testing. It's more than likely the result of an error in their API causing HTML to be served instead of the requested data.

@Zucovsky can you please open https://api.audd.io in your browser and send the response you see together with your IP address to hello@audd.io?