Show the real reason when BamBuddy is unavailable
Deploy HickLab3D Dashboard / Deploy to production (push) Successful in 25s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Hickmeister
2026-10-11 20:17:15 +01:00
co-authored by Claude Sonnet 5.5
parent f3a3776cd5
commit 8a281b5b61
+14 -1
View File
@@ -4,7 +4,10 @@ namespace App\Http\Controllers;
use App\Services\Bambuddy; use App\Services\Bambuddy;
use Closure; use Closure;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Http\Client\RequestException;
use Illuminate\View\View; use Illuminate\View\View;
use RuntimeException;
use Throwable; use Throwable;
class BambuddyController extends Controller class BambuddyController extends Controller
@@ -18,7 +21,7 @@ class BambuddyController extends Controller
$printers = $bambuddy->printers(); $printers = $bambuddy->printers();
} catch (Throwable $exception) { } catch (Throwable $exception) {
report($exception); report($exception);
$integrationError = 'BamBuddy is unavailable. Check its API key and connection.'; $integrationError = 'BamBuddy is unavailable. '.$this->failureReason($exception);
} }
$queue = $printers === [] ? [] : $this->optional(fn (): array => $bambuddy->queue()); $queue = $printers === [] ? [] : $this->optional(fn (): array => $bambuddy->queue());
@@ -28,6 +31,16 @@ class BambuddyController extends Controller
return view('printers.index', compact('printers', 'integrationError', 'queue', 'recentPrints', 'stats') + ['bambuddyUrl' => $bambuddy->url()]); return view('printers.index', compact('printers', 'integrationError', 'queue', 'recentPrints', 'stats') + ['bambuddyUrl' => $bambuddy->url()]);
} }
private function failureReason(Throwable $exception): string
{
return match (true) {
$exception instanceof RequestException => 'BamBuddy answered HTTP '.$exception->response->status().($exception->response->status() === 401 || $exception->response->status() === 403 ? ' — check the API key.' : '.'),
$exception instanceof ConnectionException => 'The dashboard server could not connect: '.str($exception->getMessage())->limit(160),
$exception instanceof RuntimeException => $exception->getMessage(),
default => 'Check its API key and connection.',
};
}
/** /**
* Load secondary page data without letting a failure hide the printers. * Load secondary page data without letting a failure hide the printers.
* *