I’m testing out TidByt development, and have a configurable text where you enter an image URL in a text field. A couple of questions:
- Is there a way to check for a valid URL before calling
http.get(URL)
? Otherwise I get an errorError in get
. I’d like a way to catch it. - Is there a way to check if the response from a URL is an image?
Say I have a URL that does not produce an image:
url = "<non_image_url>"
res = http.get(url) # If invalid URL - Error in get: Get <invalid_url>: dial tcp <invalid_url>: connect: connection refused
img = res.body()
return render.Root(
child = render.Padding(
child = render.Image(src = img), # Error in Image: decoding image data: image: unknown format
pad = 1,
),
)
Is there a way for me to check img
is a valid image before calling render.Image?
UPDATE: Checking via res.headings content-type seems to be something I can do. Let me know if there’s a better way.