contentful / rich-text.php

Utilities for the Contentful Rich Text
https://www.contentful.com
MIT License
12 stars 9 forks source link

Asset reference mappers are hiding bugs #49

Closed e1himself closed 4 years ago

e1himself commented 4 years ago

This is the same problem as #44 but on Asset resolution.

This catch-all exception inside asset reference nodes are hiding any error occurring during the link resolution. That includes:

The problem with this approach is that the external code doesn't know if there was an exception. It just gets an incomplete object with some assets not fetched. The problem gets worse when these incomplete objects get cached (in contentful SDK or on CDN). While if there was an error thrown, the asset could be refetched on next request.

An example of code that causes this problem:

try {
    /** @var AssetInterface $asset */
    $asset = $linkResolver->resolveLink(
        new Link($linkData['id'], $linkData['linkType'])
    );
} catch (\Throwable $exception) {
    throw new MapperException($data);
}