0

I am currently working on an IoT project which requires service discovery (I am in the Android side). I decided to use react-native-zeroconf and I encountered a problem.

There is a warning Error: Request failed with status code 500 once I called .scan() method. I have already added permission into the AndroidManifest file. Thank you in advance.

Edit: remove async from function

export function scanmDNS() {
  const zeroconf = new Zeroconf();
  zeroconf.scan();
  const res = zeroconf.getServices();
  console.log({ res });
  zeroconf.stop();
}
Object {
  "res": Object {},
}

Possible Unhandled Promise Rejection (id: 0):
Error: Request failed with status code 500
createError@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:224752:26
settle@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:224742:25
onloadend@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:224619:15
dispatchEvent@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:33843:31
setReadyState@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:32985:29
__didCompleteResponse@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:32783:29
emit@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:4940:42
__callFunction@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:5979:36
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:5707:31
__guard@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:5933:15
callFunctionReturnFlushedQueue@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:5706:21
callFunctionReturnFlushedQueue@[native code]
Possible Unhandled Promise Rejection (id: 1):
ChuChuwi
  • 719
  • 1
  • 8
  • 13

1 Answers1

0

There are two ways to handle Promises, since you're using async/await syntax your response should use the await keyword also you are wrapping your response in an object which you shouldn't (without assigning it to a property).

const res = await zeroconf.getServices();

console.log(res)

The other way would be

zeroconf.getServices()
.then((res) => { 
  console.log(res) //do whatever you want to do with your response here
})
.catch((err) => { 
  console.log(err) //handle errors here.
}

Not sure if this will solve your problem but hope it leads you to your solution :)

Tyler Thomas
  • 120
  • 1
  • 8
  • zeroconf.getServices() is actually not an asynchronous function, I needed async to do other functionalities that I didn't include in the code. Sorry for not considering. – ChuChuwi Jan 20 '22 at 16:03
  • Have you tried changing console.log({res}) to console.log(res)? – Tyler Thomas Jan 21 '22 at 09:41
  • console.log({res}) would give me the log of {res: Result Object} which is easier to debug for me. However, res is an empty object :( – ChuChuwi Jan 21 '22 at 14:26