Skip to content

Exceptions

The module provides several custom exceptions for handling various error conditions.

Core Exceptions

ApiNotEnabledException

Thrown when attempting to use the API while it's disabled.

ContextNotFoundException

Thrown when a requested document context cannot be found.

DocumentNotFoundException

Thrown when a requested Prismic document doesn't exist.

RouteNotFoundException

Thrown when a requested route cannot be found.

StaticBlockNotFoundException

Thrown when a static block cannot be found.

Implementation

Exception Handling

try {
    $document = $this->getDocument();
} catch (DocumentNotFoundException $e) {
    // Handle missing document
} catch (ContextNotFoundException $e) {
    // Handle missing context
}

Configuration-Based Handling

The module can be configured to handle exceptions differently based on environment:

<prismicio>
    <content>
        <throw_exceptions>0</throw_exceptions>
    </content>
</prismicio>

Best Practices

  1. Exception Types
  2. Use specific exceptions
  3. Maintain hierarchy
  4. Document error conditions

  5. Error Handling

  6. Graceful degradation
  7. Proper logging
  8. User-friendly messages

  9. Development

  10. Debug mode considerations
  11. Proper error reporting
  12. Exception documentation