Skip to content

Commit

Permalink
[bridge] fitur handle erorr jika bpjs bridging down atau gangguan
Browse files Browse the repository at this point in the history
  • Loading branch information
virusphp committed Apr 6, 2022
1 parent 1b85bb9 commit f0616c0
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/Bpjs/Bridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Bpjs\Bridging;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;

class Bridge
{
Expand All @@ -23,10 +24,8 @@ public function httpGet($endpoint, $header)
$result = $response->getBody()->getContents();
return $result;
} catch (RequestException $e) {
$result = $e->getRequest();
if ($e->hasResponse()) {
$result = $e->getResponse();
}
$result = $this->responseError($e);
return $result;
}
}

Expand All @@ -37,10 +36,8 @@ public function httpPost($endpoint, $header, $data)
$result = $response->getBody()->getContents();
return $result;
} catch (RequestException $e) {
$result =$e->getRequest();
if ($e->hasResponse()) {
$result = $e->getResponse();
}
$result = $this->responseError($e);
return $result;
}
}

Expand All @@ -51,10 +48,8 @@ public function httpPut($endpoint, $header, $data)
$result = $response->getBody()->getContents();
return $result;
} catch (RequestException $e) {
$result =$e->getRequest();
if ($e->hasResponse()) {
$result = $e->getResponse();
}
$result = $this->responseError($e);
return $result;
}
}

Expand All @@ -65,10 +60,21 @@ public function httpDelete($endpoint, $header, $data)
$result = $response->getBody()->getContents();
return $result;
} catch (RequestException $e) {
$result =$e->getRequest();
if ($e->hasResponse()) {
$result = $e->getResponse();
}
$result = $this->responseError($e);
return $result;
}
}

protected function responseError($error)
{
$result = [
'metaData' => [
'code' => $error->getCode(),
'message' => $error->getMessage()
],
'response' => null
];

return json_encode($result);
}
}

0 comments on commit f0616c0

Please sign in to comment.