microlinkhq / sdk

Make any URL embeddable. Turn any URL into a beautiful link preview.

Home Page:https://microlink.io/sdk

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crashed with invalid link

alnidok opened this issue · comments

Bug Report

You can use live code at Codesandbox: React | Vanilla

Current Behavior

I have text with link and I want to preview this link. JS crash if link is invalid or broken or something else.
There are examples in sandbox above.

It happens because endpoint https://api.microlink.io/?url=https://invalid-link returns "<required> an URL for getting content." in data.url.

const { hostname } = new URL(href)

new URL('<required> an URL for getting content.') throw error.

Expected behavior/code
Preview won't show but without crash.

Hello, and thanks a lot for reporting.

I improved this behavior at Microlink API:

https://api.microlink.io/?url=https://invalid-link

It returns now a proper error – can you check at your code level? it's now working as expected?

Better, but there is a problem with method fetchFromApi (@microlink/mql)
ReferenceError: Buffer is not defined

debug screenshot
error screenshot

Thanks a lot for taking care about this 🙏

I released @microlink/mql@0.10.20 that address the issue.

Also, created a tiny playground to make easy reproduce errors in the future:
https://mql.microlink.io/?url=https://invald-url

If you just remove node_modules and install again, the new version should be there; can you confirm? 🙂

Yes, now it works good. Thank you!