TryGhost / Ghost

Independent technology for modern publishing, memberships, subscriptions and newsletters.
https://ghost.org
MIT License
46.91k stars 10.21k forks source link

Improve error message for YouTube videos that disabled embedding #16048

Closed shafy closed 1 year ago

shafy commented 1 year ago

Issue Summary

EDIT: I've figured out that this specific YouTube doesn't allow embedding. Maybe you could improve the error message shown to the user if you get the Unauthorized message (see below) so this causes less confusion. I have also updated the issue title to reflect this. I'm leaving the following text here as was to leave the context.


In general, YouTube embedding works. But this specific returns an error: https://www.youtube.com/watch?v=5f-JlzBuUUU.

CleanShot 2022-12-25 at 20 10 24@2x

The request is the following:

https://cassandradispatch.org/ghost/api/admin/oembed/?url=https://www.youtube.com/watch?v=5f-JlzBuUUU&type=embed

The error response is the following:

{
    "errors": [
        {
            "message": "Internal server error, cannot read oembed.",
            "context": "invalid json response body at https://www.youtube.com/oembed?format=json&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D5f-JlzBuUUU reason: Unexpected token U in JSON at position 0",
            "type": "InternalServerError",
            "details": null,
            "property": null,
            "help": null,
            "code": null,
            "id": "e01223d0-8487-11ed-94c3-8df7a8a46270",
            "ghostErrorCode": null
        }
    ]
}

This is becaue the request https://www.youtube.com/oembed?format=json&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D5f-JlzBuUUU

Returns Unauthorized as the response body.

Steps to Reproduce

  1. Create a new post (or edit an existing one)
  2. Click the "plus" sign to add a new bloc and choose "YouTube"
  3. Paste this URL: https://www.youtube.com/watch?v=5f-JlzBuUUU
  4. See the error

Ghost Version

5.26.3

Node.js Version

16.18.1

How did you install Ghost?

Hetzner, Ubuntu 22.04.1

Database type

MySQL 8

Browser & OS version

No response

Code of Conduct

ErisDS commented 1 year ago

Hey there, thank you so much for the detailed bug report.

That does look like something that shouldn't happen! A PR to fix this issue would be very welcome 🙂

shafy commented 1 year ago

Thanks @ErisDS ! I'm not sure I have a lot of spare time in the next weeks, so if anybody else reading this wants to swoop in, feel free! Otherwise, I'll keep it in mind and might get back to it eventually 😇

harshmange44 commented 1 year ago

@ErisDS @shafy Hey, I would like to work on this one

cmraible commented 1 year ago

This issue seems to duplicate issue 10624. I traced the problem back to oembed-extractor, which Ghost uses to extract the oembed payload from the provider (in this case Youtube). The extract(url) function doesn't catch the error and passes the payload directly back to Ghost, which is expecting JSON but instead receives Unauthorized and gets confused.

Opened issue 168 with oembed-extractor to see if the author can add in some error handling for this case — issue 39 (same issue) was previously closed because the author couldn't replicate the issue, but I've been able to reliably replicate it with the Youtube URL linked above so hopefully should be able to get it resolved this time.

cmraible commented 1 year ago

Status update: PR is ready and approved to merge, but we want to be careful with deployment/rollout.

Last time we updated the oembed-parser package in Pro (~1 year ago), it created a lot of 422 errors. Since we are again trying to upgrade the oembed-parser package again, we want to carefully deploy this to a subset of Pro users, monitor and if successful, then deploy more widely. As such, we are waiting on the right timing to do this merge so that we have a little time to babysit this rollout.

cmraible commented 1 year ago

New error message:

CleanShot 2023-05-04 at 16 05 37@2x

Fixed with this commit: https://github.com/TryGhost/Ghost/commit/27e4523aec3790d2280fbc267d178e145f8b9079