错误处理

This commit is contained in:
iVampireSP.com 2022-12-06 17:35:57 +08:00
parent 2336eb5754
commit 13730c5dea
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
2 changed files with 75 additions and 65 deletions

View File

@ -2,8 +2,10 @@
namespace App\Http\Controllers\Admin; namespace App\Http\Controllers\Admin;
use App\Exceptions\EmqxSupportException;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Support\EmqxSupport; use App\Support\EmqxSupport;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Pagination\Paginator; use Illuminate\Pagination\Paginator;
@ -15,11 +17,15 @@ public function index(Request $request)
{ {
$emqx = new EmqxSupport(); $emqx = new EmqxSupport();
try {
$clients = $emqx->clients([ $clients = $emqx->clients([
'clientid' => $request->client_id, 'clientid' => $request->client_id,
'username' => $request->username, 'username' => $request->username,
'page' => $request->page, 'page' => $request->page,
]); ]);
} catch (EmqxSupportException|ConnectionException $e) {
return back()->with('error', $e->getMessage());
}
// dd($clients); // dd($clients);
return view('admin.device.index', compact('clients')); return view('admin.device.index', compact('clients'));

View File

@ -35,6 +35,7 @@
</thead> </thead>
<tbody> <tbody>
@if(isset($clients))
@foreach($clients['data'] as $c) @foreach($clients['data'] as $c)
<tr> <tr>
<td> <td>
@ -81,9 +82,11 @@
</td> </td>
</tr> </tr>
@endforeach @endforeach
@endif
</tbody> </tbody>
</table> </table>
@if(isset($clients))
<div class="d-none flex-sm-fill d-sm-flex align-items-sm-center justify-content-sm-end"> <div class="d-none flex-sm-fill d-sm-flex align-items-sm-center justify-content-sm-end">
<div> <div>
<ul class="pagination"> <ul class="pagination">
@ -101,5 +104,6 @@
</ul> </ul>
</div> </div>
</div> </div>
@endif
@endsection @endsection