400 Bad Request

0

The call to AWS Rekognition API request "describeCollection" returns "400 Bad Request" and crashes instead of throwing an exception. An invalid collection ID is NOT a fatal error. Why doesn't the API throw an exception? Here's my code: try { $result = $aws_client->client->describeCollection([ 'CollectionId' => $collection_id, // REQUIRED ]); } catch( ResourceNotFoundException $e ) { $errmsg = "describeCollection exception:" . $e-getMessage(); return; } catch ( Exception $e ) { $errmsg = "describeCollection exception:" . $e-getMessage(); return; } An here's the response: Aws \ Rekognition \ Exception \ RekognitionException PHP 8.1.18 10.10.0 Error executing "DescribeCollection" on "https://rekognition.ap-southeast-2.amazonaws.com"; AWS HTTP error: Client error: POST https://rekognition.ap-southeast-2.amazonaws.com resulted in a 400 Bad Request response: {"__type":"ResourceNotFoundException","Code":"ResourceNotFoundException","Message":"Collection:dev_gallery_32 not found! (truncated...) ResourceNotFoundException (client): Collection:dev_gallery_32 not found! - {"__type":"ResourceNotFoundException","Code":"ResourceNotFoundException","Message":"Collection:dev_gallery_32 not found!"}

Paul
已提問 3 個月前檢視次數 222 次
1 個回答
1

Hi Paul,

From AWS SDK PHP reference below, the client would throw a RekognitionException, and "ResourceNotFoundException" is the errorType within the exception.

Could you try if the following modification works?

try { 
  $result = $aws_client->client->describeCollection([ 'CollectionId' => $collection_id, // REQUIRED ]); 
} catch( RekognitionException $e ) { 
  $errortype = $e->getAwsErrorType();
  return; 
}

https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.Rekognition.Exception.RekognitionException.html

AWS
已回答 3 個月前
  • Did you use the correct full namespace Aws\Rekognition\Exception\RekognitionException?

    use Aws\Rekognition\Exception\RekognitionException as RekognitionException;

  • Hi, Thanks for your response. I tried your suggestion but, unfortunately, I got the same error message. Note, that the code works fine with a valid collection ID. In response to your latest comment, I added the namespace as suggested. At least, it stopped crashing, but still doesn't throw an exception. It continues past the call to describeCollection(), and continues as if there's no error.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南