microsoftgraph / microsoftgraph/msgraph-sdk-php

Make exception handling experience intuitive

Offen
#1,034 1 Kommentar 3 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

question v2: feedback
Vorherrschende Sprache
PHP
Sterne
669
Forks
150
Ø Merge
15 Std. 21 Min.
Gemergte PRs (30 T.)
3

Beschreibung

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
  }
}

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit Generated/Models/ODataErrors/ODataError.php und MainError und verfolge dann den Fehler durch GuzzleRequestAdapter::throwFailedResponse und SiteItemRequestBuilder.php. Reproduziere die fehlende Meldung mit dem Beispiel sitesById(...)->get()->wait(). Als abgeschlossen gilt die Aufgabe, wenn die API-Fehlermeldung über ApiException::getMessage() verfügbar ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
php
Bereich
api, backend
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.