Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dealing defensively with rubbish field entries #10

Closed
iparr opened this issue Mar 28, 2019 · 9 comments
Closed

Dealing defensively with rubbish field entries #10

iparr opened this issue Mar 28, 2019 · 9 comments

Comments

@iparr
Copy link

iparr commented Mar 28, 2019

My content editors are wonderful, but I want to ensure that even if they put something dumb in the field that errors are handled as gracefully as possible.

I am using {{ entry.field.render }} and it works well (thanks!) but if an invalid value is added to the oEmbed field, then the whole template will error: Embed\Exceptions\InvalidUrlException

Is there a way I can handle this more gracefully? I'd like the page to render with the video simply missing.

@reganlawton
Copy link
Member

@iparr I believe this is 100% valid. I’ll make it do errors only display in DEV via the twig variable output.

In anything other I’ll just error to log file.

@reganlawton
Copy link
Member

@iparr I've finally got a chances to push changes to the plugin I made this morning tagged v1.1.3.

It comes with better sub prop handling, if the property is missing, as well as a new valid methods as a TWIG variable and new method on the field. See README for more information.

@iparr
Copy link
Author

iparr commented Apr 11, 2019

I've tested this and it's allowed me check for valid oEmbeds in a much nicer way. Thanks! Great work.

@reganlawton
Copy link
Member

Thanks for the issue report and glad it’s working for you now. 👍

@iparr
Copy link
Author

iparr commented Nov 2, 2020

Hey, I think this has regressed or alternatively I've misunderstood something.

I have invalid fields that I'd like to test for in Twig.

I'm using:

{% block.embed.valid %}
…

or {{ block.embedId.valid }} or {% if craft.oembed.valid(block.embedId.valid) %}… and both still result in errors.

So how is best to test for valid fields on the front-end?

@iparr
Copy link
Author

iparr commented Mar 17, 2021

I would like this re-opened if possible @reganlawton

I'm still not sure how to test for embeds that are invalid.

For example, when a URL like this https://thesludgelord.bandcamp.com/album/metal is rendered invalid because an owner removes it, then my website breaks with a Caused by: Embed\Exceptions\InvalidUrlException error.

How is best to combat this?

@reganlawton reganlawton reopened this Mar 17, 2021
@reganlawton
Copy link
Member

I'll have to look into this I've been smashed lately when investor deadlines but have a few tweaks needing to be done to the application

@reganlawton
Copy link
Member

@iparr I have updated the handling a bit better if you want to take a look at this in the latest v1.3.9

@iparr
Copy link
Author

iparr commented Jun 17, 2021

Sorry, if I use it with the same example as above, I still get:

Serialization of 'class@anonymous' is not allowed
↵
Caused by: Embed\Exceptions\InvalidUrlException
Invalid url 'https://thesludgelord.bandcamp.com/album/metal' (Status code 404)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants