Perbaikan handle error dawai dan webhook sementara #96
@@ -9,8 +9,10 @@ use Carbon\Carbon;
|
||||
use Error;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use GuzzleHttp\Exception\ServerException;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Str;
|
||||
use Throwable;
|
||||
|
||||
class DawaiService
|
||||
@@ -371,8 +373,16 @@ class DawaiService
|
||||
$data = json_decode($response->getBody()->getContents(), true)['data'];
|
||||
|
||||
return $data;
|
||||
} catch (ServerException $th) {
|
||||
$body = (string) $th->getResponse()->getBody();
|
||||
$penyebab = preg_match('/\b\w*(?:Error|Exception):[^\r\n<]+/', html_entity_decode($body), $match)
|
||||
? trim($match[0])
|
||||
: Str::limit(trim(strip_tags($body)), 200);
|
||||
|
||||
Log::error('DAWAI : listStatusPresensi gagal - server DAWAI error (HTTP '.$th->getResponse()->getStatusCode().') bukan dari Verifikator, perbaiki di sisi DAWAI. Penyebab: '.$penyebab);
|
||||
throw new Error($th->getMessage(), 500);
|
||||
} catch (Throwable $th) {
|
||||
Log::error('DAWAI : '.$th->getMessage());
|
||||
Log::error('DAWAI : listStatusPresensi gagal - '.$th->getMessage());
|
||||
throw new Error($th->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,27 +24,28 @@ class VerifikatorWebhookService
|
||||
|
||||
public function kirimIzin(PengajuanPresensi $pengajuan, string $status, ?string $alasan = null): bool
|
||||
{
|
||||
try {
|
||||
$response = Http::timeout(5)
|
||||
->post(self::URL, [
|
||||
'jenis' => 'izin',
|
||||
'nip' => $pengajuan->nip,
|
||||
'tanggal' => Carbon::parse($pengajuan->tanggal_mulai)->format('Y-m-d'),
|
||||
'kategori' => $this->slugKategori($pengajuan->getRawOriginal('kategori')),
|
||||
'status' => $status,
|
||||
'alasan' => $alasan ?? '',
|
||||
]);
|
||||
|
||||
if ($response->successful()) {
|
||||
Log::info("Webhook Verifikator berhasil: $pengajuan->nip ($status)");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Log::warning("Webhook Verifikator gagal: $pengajuan->nip ($status) - HTTP {$response->status()}");
|
||||
} catch (Throwable $th) {
|
||||
Log::error("Webhook Verifikator error: $pengajuan->nip ($status) - ".$th->getMessage());
|
||||
}
|
||||
// Webhook Verifikator dinonaktifkan sementara.
|
||||
// try {
|
||||
// $response = Http::timeout(5)
|
||||
// ->post(self::URL, [
|
||||
// 'jenis' => 'izin',
|
||||
// 'nip' => $pengajuan->nip,
|
||||
// 'tanggal' => Carbon::parse($pengajuan->tanggal_mulai)->format('Y-m-d'),
|
||||
// 'kategori' => $this->slugKategori($pengajuan->getRawOriginal('kategori')),
|
||||
// 'status' => $status,
|
||||
// 'alasan' => $alasan ?? '',
|
||||
// ]);
|
||||
//
|
||||
// if ($response->successful()) {
|
||||
// Log::info("Webhook Verifikator berhasil: $pengajuan->nip ($status)");
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// Log::warning("Webhook Verifikator gagal: $pengajuan->nip ($status) - HTTP {$response->status()}");
|
||||
// } catch (Throwable $th) {
|
||||
// Log::error("Webhook Verifikator error: $pengajuan->nip ($status) - ".$th->getMessage());
|
||||
// }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user