Skip to content

Commit c44b6d8

Browse files
author
armando
committed
Migliorata gestione errori su client e su costruzione model
1 parent eb42966 commit c44b6d8

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/Client.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ private function curl( string $verb, string $request, \JsonSerializable $json =
103103
}
104104

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

src/Types/GenericType.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ public function __construct( string $json = null ) {
1717
}
1818

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

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

2629
if( is_object($value) ) {

0 commit comments

Comments
 (0)