AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AiException.php 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Ai;
  3. use RuntimeException;
  4. use Throwable;
  5. /**
  6. * Anything that goes wrong while asking an AI model.
  7. */
  8. final class AiException extends RuntimeException
  9. {
  10. /** The app is not set up correctly, for example a missing API key. */
  11. public const string SETUP = 'setup';
  12. /** The provider failed: network, overload, rate limit, refusal. */
  13. public const string PROVIDER = 'provider';
  14. /** The AI answered, but the answer is not a usable store plan. */
  15. public const string INVALID_RESULT = 'invalid_result';
  16. public function __construct(string $message, public readonly string $reason = self::PROVIDER, ?Throwable $previous = null)
  17. {
  18. parent::__construct($message, 0, $previous);
  19. }
  20. /**
  21. * A short message that is safe to show to a merchant.
  22. */
  23. public function friendlyMessage(): string
  24. {
  25. return match ($this->reason) {
  26. self::SETUP => 'The AI service is not set up yet. Please contact support.',
  27. self::INVALID_RESULT => 'The AI returned a design we could not use. Please try again.',
  28. default => 'The AI service had a problem. Please try again in a moment.',
  29. };
  30. }
  31. }