0 レビュー
1 回答
php-Geocodio APIを使用してバッチジオコーディングリクエストを行う場合、422エラーを処理するにはどうすればよいですか?
アドレス情報を含むファイルを読み込んでいます。一部のアドレスは処理できません(エラーコード422)。処理可能なアドレスの結果を返し、エラーの場所を空白のままにするにはどうすればよいですか?
require 'myFunctions.php';
require_once '../../vendor/autoload.php';
use Stanley\Geocodio\Client;
$client = new Client('Your API key');
//Read in address data.
$AddressData = file('address.txt');
//Send a request to the API.
$location = $client->post($AddressData);
わからない
0
レビュー
答え :
解決策:
私は APIがエラーを自動的に処理し、空白のままにしていると思います。いいえ? (エラーのスクリーンショットを共有した場合に役立ちます)-しかし、とにかく、そのようなエラー(例外)をキャッチすることを意味する場合は、 Geocodio(ソース):
An HTTP 403 error raises a GeocodioAuthError
An HTTP 422 error raises a GeocodioDataError and the error message will be reported through the exception
An HTTP 5xx error raises a GeocodioServerError
An unmatched non-200 response will simply raise Exception
あなたの場合、処理できないアドレスについては、 GeocodioDataError
例外をキャッチする必要があります。とにかく購入することは、サポートされているものをすべてキャッチすることをお勧めします(キャッチ'エムオール)。私はあなたがこのようなことをすることができるはずだと思います:
try
{{
$ location = $ client-> post($ AddressData);
}
catch(\ Stanley \ Geocodio \ GeocodioAuthError)
{{
//何かをする
}
catch(\ Stanley \ Geocodio \ GeocodioDataError)
{{
//何かをする
}
catch(\ Stanley \ Geocodio \ GeocodioServerError)
{{
//何かをする
}
キャッチ(\ Exception $ e)
{{
//何かをする
}
添付のスクリーンショットでは、 Guzzle
を使用していることがわかります。 Guzzle
では、次のような例外をキャッチできます(続きを読む):
try
{{
$ location = $ client-> post($ AddressData);
}
キャッチ(Guzzle \ Http \ Exception \ BadResponseException $ e)
{{
//何かをする
}
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。