flarum/framework · error · ResourceNotFoundException

ResourceNotFoundException

Error message

ResourceNotFoundException

What it means

Thrown by JsonApi::getCollection when no registered collection matches the requested type, either by exact name key or by instance-of check against the class string. Means the API was asked for a resource type that has never been registered with this JsonApi instance (missing extension, typo in type, or collection not registered in the extension's extend.php).

Solutions

  1. Register the collection via the JsonApi registerCollection (or the corresponding extender) so the type resolves
  2. Correct the type/class string in the request or caller so it matches a registered collection
  3. Confirm the extension that defines the resource is enabled
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at framework/core/src/Api/JsonApi.php:95 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of flarum/framework@4b939f6853 (2026-09-15). Data as JSON: /api/errors/3c10d4010991d024. Report an issue: GitHub.

Appendix: source

Thrown at framework/core/src/Api/JsonApi.php:95

    /**
     * Get a collection by name or class.
     *
     * @throws ResourceNotFoundException if the collection has not been defined.
     */
    public function getCollection(string $type): Collection
    {
        if (isset($this->collections[$type])) {
            return $this->collections[$type];
        }

        foreach ($this->collections as $instance) {
            if ($instance instanceof $type) {
                return $instance;
            }
        }

        throw new ResourceNotFoundException($type);
    }

    /**
     * Get a resource by type or class.
     *
     * @throws ResourceNotFoundException if the resource has not been defined.
     */
    public function getResource(string $type): Resource
    {
        if (isset($this->resources[$type])) {
            return $this->resources[$type];
        }

        foreach ($this->resources as $instance) {
            if ($instance instanceof $type) {
                return $instance;
            }
        }

View on GitHub (pinned to 4b939f6853)