microsoftgraph / microsoftgraph/msgraph-sdk-php
Make exception handling experience intuitive
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- PHP
- Estrellas
- 669
- Forks
- 150
- Merge medio
- 15 h 21 min
- PR fusionados (30 d)
- 3
Descripción
I'm encoutering an issue with using ApiException to get exceptions in v2.0.0 RC9. The message variable is always blank with exceptions for most commands regarding working with sites, drives, and files. The exception is in there, just buried inside of a private 'error' variable.
Example of getting a site that doesn't exist:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
require_once __DIR__ . '/vendor/autoload.php';
use Microsoft\Graph\Generated\Models;
use Microsoft\Graph\GraphRequestAdapter;
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Kiota\Authentication\Oauth\ClientCredentialContext;
use Microsoft\Kiota\Authentication\PhpLeagueAuthenticationProvider;
try {
$tokenRequestContext = new ClientCredentialContext(
$tenantId,
$clientId,
$clientSecret
);
$scopes = ['https://graph.microsoft.com/.default'];
$authProvider = new PhpLeagueAuthenticationProvider($tokenRequestContext, $scopes);
$requestAdapter = new GraphRequestAdapter($authProvider);
$graphServiceClient = new GraphServiceClient($requestAdapter);
/** @var Models\Site $site */
$site = $graphServiceClient->sitesById($siteId)->get()->wait();
} catch (ApiException $ex) {
echo $ex->getMessage();
}
?>
This returns the a blank $ex->message, and the following var_dump($ex):
object(Microsoft\Graph\Generated\Models\ODataErrors\ODataError)#59 (9) {
["message":protected]=>
string(0) ""
["string":"Exception":private]=>
string(0) ""
["code":protected]=>
int(0)
["file":protected]=>
string(131) "/home/username/test/vendor/microsoft/microsoft-graph/src/Generated/Models/ODataErrors/ODataError.php"
["line":protected]=>
int(37)
["trace":"Exception":private]=>
array(7) {
[0]=>
array(5) {
["file"]=>
string(114) "/home/username/test/vendor/microsoft/kiota-serialization-json/src/JsonParseNode.php"
["line"]=>
int(107)
["function"]=>
string(28) "createFromDiscriminatorValue"
["class"]=>
string(55) "Microsoft\Graph\Generated\Models\ODataErrors\ODataError"
["type"]=>
string(2) "::"
}
[1]=>
array(5) {
["file"]=>
string(114) "/home/username/test/vendor/microsoft/kiota-http-guzzle/src/GuzzleRequestAdapter.php"
["line"]=>
int(308)
["function"]=>
string(14) "getObjectValue"
["class"]=>
string(48) "Microsoft\Kiota\Serialization\Json\JsonParseNode"
["type"]=>
string(2) "->"
}
[2]=>
array(5) {
["file"]=>
string(114) "/home/username/test/vendor/microsoft/kiota-http-guzzle/src/GuzzleRequestAdapter.php"
["line"]=>
int(88)
["function"]=>
string(19) "throwFailedResponse"
["class"]=>
string(41) "Microsoft\Kiota\Http\GuzzleRequestAdapter"
["type"]=>
string(2) "->"
}
[3]=>
array(5) {
["file"]=>
string(99) "/home/username/test/vendor/php-http/promise/src/FulfilledPromise.php"
["line"]=>
int(35)
["function"]=>
string(30) "Microsoft\Kiota\Http\{closure}"
["class"]=>
string(41) "Microsoft\Kiota\Http\GuzzleRequestAdapter"
["type"]=>
string(2) "->"
}
[4]=>
array(5) {
["file"]=>
string(114) "/home/username/test/vendor/microsoft/kiota-http-guzzle/src/GuzzleRequestAdapter.php"
["line"]=>
int(98)
["function"]=>
string(4) "then"
["class"]=>
string(29) "Http\Promise\FulfilledPromise"
["type"]=>
string(2) "->"
}
[5]=>
array(5) {
["file"]=>
string(135) "/home/username/test/vendor/microsoft/microsoft-graph/src/Generated/Sites/Item/SiteItemRequestBuilder.php"
["line"]=>
int(277)
["function"]=>
string(9) "sendAsync"
["class"]=>
string(41) "Microsoft\Kiota\Http\GuzzleRequestAdapter"
["type"]=>
string(2) "->"
}
[6]=>
array(5) {
["file"]=>
string(64) "/home/username/test/graph-bug.php"
["line"]=>
int(32)
["function"]=>
string(3) "get"
["class"]=>
string(59) "Microsoft\Graph\Generated\Sites\Item\SiteItemRequestBuilder"
["type"]=>
string(2) "->"
}
}
["previous":"Exception":private]=>
NULL
["additionalData":"Microsoft\Graph\Generated\Models\ODataErrors\ODataError":private]=>
array(0) {
}
["error":"Microsoft\Graph\Generated\Models\ODataErrors\ODataError":private]=>
object(Microsoft\Graph\Generated\Models\ODataErrors\MainError)#80 (6) {
["additionalData":"Microsoft\Graph\Generated\Models\ODataErrors\MainError":private]=>
array(1) {
["innerError"]=>
array(3) {
["date"]=>
string(19) "2022-10-17T16:23:06"
["request-id"]=>
string(36) "80ddeda1-e38d-41fc-a42d-6e943d3b16cd"
["client-request-id"]=>
string(36) "7ee8f8ec-2bd6-4609-aa90-3a2356efa61f"
}
}
["code":"Microsoft\Graph\Generated\Models\ODataErrors\MainError":private]=>
string(12) "itemNotFound"
["details":"Microsoft\Graph\Generated\Models\ODataErrors\MainError":private]=>
NULL
["innererror":"Microsoft\Graph\Generated\Models\ODataErrors\MainError":private]=>
NULL
["message":"Microsoft\Graph\Generated\Models\ODataErrors\MainError":private]=>
string(33) "Requested site could not be found"
["target":"Microsoft\Graph\Generated\Models\ODataErrors\MainError":private]=>
NULL
}
}
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Empieza por Generated/Models/ODataErrors/ODataError.php y MainError, y luego sigue el fallo a través de GuzzleRequestAdapter::throwFailedResponse y SiteItemRequestBuilder.php. Reproduce el mensaje que falta con el ejemplo sitesById(...)->get()->wait(). Se considera completado cuando el mensaje de error de la API está disponible mediante ApiException::getMessage().
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- php
- Área
- api, backend
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100