feat: add error handling (#14)
* Remove commented out crap * Update theme to use some colors from catppuccin, add error handling for API/DB
This commit is contained in:
		
					parent
					
						
							
								3fc99d1c9d
							
						
					
				
			
			
				commit
				
					
						9a0d3a4ccc
					
				
			
		
					 8 changed files with 85 additions and 15 deletions
				
			
		| 
						 | 
				
			
			@ -13,10 +13,22 @@ function degreesToCompassDirection($degrees) {
 | 
			
		|||
    return $cardinalDirections[round($degrees*16/360)];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
$data = json_decode(file_get_contents($api_root.'/weather'));
 | 
			
		||||
$updated = gmdate('H:i Y-m-d', $data->updated);
 | 
			
		||||
$data = $data->current;
 | 
			
		||||
$api_alive = true;
 | 
			
		||||
 | 
			
		||||
try {
 | 
			
		||||
    $data = file_get_contents($api_root.'/weather');
 | 
			
		||||
} catch (Exception $e) {
 | 
			
		||||
    $api_alive = false;
 | 
			
		||||
}
 | 
			
		||||
@endphp
 | 
			
		||||
@if (!$api_alive)
 | 
			
		||||
    @include('components.errors.api-error')
 | 
			
		||||
@else
 | 
			
		||||
    @php
 | 
			
		||||
        $data = json_decode(file_get_contents($api_root.'/weather'));
 | 
			
		||||
        $updated = gmdate('H:i Y-m-d', $data->updated);
 | 
			
		||||
        $data = $data->current;
 | 
			
		||||
    @endphp
 | 
			
		||||
<table class="info-table">
 | 
			
		||||
    <caption>
 | 
			
		||||
        <h1>Local Weather</h1>
 | 
			
		||||
| 
						 | 
				
			
			@ -45,4 +57,5 @@ function degreesToCompassDirection($degrees) {
 | 
			
		|||
</table>
 | 
			
		||||
<br>
 | 
			
		||||
<small><i>(Last Update: {{ $updated }})</i></small>
 | 
			
		||||
@endif
 | 
			
		||||
@stop
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue