src/Client.php
private function decodeJson( $json ) {
		$error = $errorMsg = null;
		$return = json_decode( $json );
		if ( $return === null && trim( $json ) !== 'null' ) {
			$error = json_last_error();
			$errorMsg = json_last_error_msg();
		} elseif ( !$return || !is_object( $return ) ) {
			$error = 128;
			$errorMsg = 'Response must be an object';
		}

		if ( $error ) {
			$this->logger->error(
				'Failed to decode server response as JSON: {message}',
				[
					'response' => $json,
					'code' => json_last_error(),
					'message' => json_last_error_msg(),
				]
			);
			throw new Exception( 'Decoding server response failed: ' . json_last_error_msg()
				. " (Raw response: $json)" );
		}
		return $return;
	}
private function decodeJson( $json ) {
		$error = $errorMsg = null;
		$return = json_decode( $json );
		if ( $return === null && trim( $json ) !== 'null' ) {
			$error = json_last_error();
			$errorMsg = json_last_error_msg();
		} elseif ( !$return || !is_object( $return ) ) {
			$error = 128;
			$errorMsg = 'Response must be an object';
		}

		if ( $error ) {
			$this->logger->error(
				'Failed to decode server response as JSON: {message}',
				[
					'response' => $json,
					'code' => json_last_error(),
					'message' => json_last_error_msg(),
				]
			);
			throw new Exception( 'Decoding server response failed: ' . json_last_error_msg()
				. " (Raw response: $json)" );
		}
		return $return;
	}
private function decodeJson ( $ json ) { $ error = $ errorMsg = null ; $ return = json_decode ( $ json ) ; if ( $ return === null && trim ( $ json ) !== 'null' ) { $ error = json_last_error ( ) ; $ errorMsg = json_last_error_msg ( ) ; } elseif ( ! $ return || ! is_object ( $ return ) ) { $ error = 128 ; $ errorMsg = 'Response must be an object' ; } if ( $ error ) { $ this -> logger -> error ( 'Failed to decode server response as JSON: {message}' , [ 'response' => $ json , 'code' => json_last_error ( ) , 'message' => json_last_error_msg ( ) , ] ) ; throw new Exception ( 'Decoding server response failed: ' . json_last_error_msg ( ) . " (Raw response: $json)" ) ; } return $ return ; }
Like json_decode but with sane error handling.
Assumes that null is not a valid value for the JSON string.
@param string $json
@return mixed
@throws Exception On invalid JSON
Like json_decode but with sane error handling . Assumes that null is not a valid value for the JSON string .