Enhance runAllFetchs method in CurrencyController for error handling and response formatting

- Wrapped job dispatching calls in a try-catch block to handle potential exceptions during the fetching of currency and gold rates.
- Added JSON response for both success and error scenarios, improving the API's feedback mechanism for clients.
- Updated method documentation to reflect the return type of the method.

These changes improve the robustness and user experience of the currency and gold rates update process.
This commit is contained in:
Ümit Tunç
2025-01-20 22:11:35 +03:00
parent 5d6b9a2f48
commit 63aa362100
+17 -3
View File
@@ -16,12 +16,26 @@ class CurrencyController extends Controller
{
/**
* Dispatches all jobs to fetch currency and gold rates synchronously.
*
* @return \Illuminate\Http\JsonResponse
*/
public function runAllFetchs()
{
FetchCurrencyRates::dispatchSync();
FetchGoldRates::dispatchSync();
MergeCurrencyAndGoldRates::dispatchSync();
try {
FetchCurrencyRates::dispatchSync();
FetchGoldRates::dispatchSync();
MergeCurrencyAndGoldRates::dispatchSync();
return response()->json([
'status' => 'success',
'message' => 'All currency and gold rates have been successfully updated'
]);
} catch (\Exception $e) {
return response()->json([
'status' => 'error',
'message' => 'An error occurred while updating rates: ' . $e->getMessage()
], 500);
}
}
/**