Skip to content

Commit

Permalink
Merge pull request #56 from tonypartridge/patch-3
Browse files Browse the repository at this point in the history
Improve post request error handling
  • Loading branch information
tonypartridger authored Mar 11, 2024
2 parents 6192d9f + d440ef2 commit 138a4b1
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Xero.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ protected static function dopost($url, $params)
'authorization' => "Basic " . base64_encode(config('xero.clientId') . ":" . config('xero.clientSecret'))
])->asForm()->acceptJson()->post($url, $params);

if( $response->status((int) $response->status()) !== 200 ) {
throw new Exception($response->json()['error'] . ' - Try Refreshing Tokens, Error Code: ' . $response->status());
}

return $response->json();
} catch (Exception $e) {
return json_decode($e->getResponse()->getBody()->getContents(), true);
Expand Down

0 comments on commit 138a4b1

Please sign in to comment.