Skip to content

Commit

Permalink
Migliorata gestione errori su client e su costruzione model
Browse files Browse the repository at this point in the history
  • Loading branch information
armando committed Dec 14, 2018
1 parent eb42966 commit c44b6d8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ private function curl( string $verb, string $request, \JsonSerializable $json =
}

if ( $httpStatusCode != 200 ) {
$exception = new RequestFailureException( sprintf( 'Http request "%s%s" was wrong', $this->Endpoint, $request ) );
$exception->setResponse( new ErrorMessage( $result ) );
$errorMessage = new ErrorMessage( $result );
$exception = new RequestFailureException( sprintf( 'Http request "%s%s" was wrong. Code [%s] Message "%s"', $this->Endpoint, $request, $errorMessage->code, $errorMessage->message ) );
$exception->setResponse( $errorMessage );
throw $exception;
}

Expand Down
5 changes: 4 additions & 1 deletion src/Types/GenericType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ public function __construct( string $json = null ) {
}

$obj = json_decode( $json );
if( ! $obj ) {
throw new TypeException( sprintf( 'Invalid json for Model %s construction', get_class($this) ) );
}

foreach ( $obj as $key => $value ) {
if( ! property_exists( $this, $key ) ) {
throw new TypeException( sprintf( 'Does not exist "%s" property on model %s', $key, get_class($this) ) );
throw new TypeException( sprintf( 'Does not exist "%s" property on Model %s', $key, get_class($this) ) );
}

if( is_object($value) ) {
Expand Down

0 comments on commit c44b6d8

Please sign in to comment.