Backward compatibility breaks with error message parsing Low

Status code should be checked instead of parsing the error message to maintain the backward compatibility.

Detector ID
java/aws-parse-error-message@v1.0
Category
Common Weakness Enumeration (CWE) external icon
-

Noncompliant example

1public void branchingNoncompliant() {
2    AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withRegion(Regions.US_EAST_1).build();
3    try {
4        s3Client.doesObjectExist("bucketName", "key");
5    } catch (AmazonServiceException e) {
6        // Noncompliant: checks the status message of the exception instead of the status code.
7        if (e.getMessage().contains("bucketName")) {
8            log.info("one thing");
9        } else {
10            log.info("another thinking");
11        }
12    }
13}