Skip to content

Commit

Permalink
feat(iot-service): Add mapping for 409 status code to IotHubConflictE…
Browse files Browse the repository at this point in the history
…xception
  • Loading branch information
timtay-microsoft committed Jul 10, 2019
1 parent e1d90a1 commit 39d14a0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) Microsoft. All rights reserved.
* Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/

package com.microsoft.azure.sdk.iot.service.exceptions;

/**
* 409 Conflict
* Likely caused by trying to create a resource that already exists
*/
public class IotHubConflictException extends IotHubException
{
public IotHubConflictException()
{
this(null);
}

public IotHubConflictException(String message)
{
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ else if (404 == responseStatus)
{
throw new IotHubNotFoundException(errorMessage);
}
// Codes_SRS_SERVICE_SDK_JAVA_IOTHUBEXCEPTIONMANAGER_34_018: [The function shall throw IotHubConflictException if the Http response status equal 409]
else if (409 == responseStatus)
{
throw new IotHubConflictException(errorMessage);
}
// Codes_SRS_SERVICE_SDK_JAVA_IOTHUBEXCEPTIONMANAGER_12_005: [The function shall throw IotHubPreconditionFailedException if the Http response status equal 412]
else if (412 == responseStatus)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ public void httpResponseVerification404() throws IotHubException
IotHubExceptionManager.httpResponseVerification(response);
}

// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBEXCEPTIONMANAGER_34_018: [The function shall throw IotHubConflictException if the Http response status equal 409]
// Assert
@Test (expected = IotHubConflictException.class)
public void httpResponseVerification409() throws IotHubException
{
// Arrange
final int status = 409;
final byte[] body = { 1 };
final Map<String, List<String>> headerFields = new HashMap<>();
final byte[] errorReason = { 2, 3, 4, 5 };
HttpResponse response = new HttpResponse(status, body, headerFields, errorReason);
// Act
IotHubExceptionManager.httpResponseVerification(response);
}

// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBEXCEPTIONMANAGER_12_005: [The function shall throw IotHubPreconditionFailedException if the Http response status equal 412]
// Assert
@Test (expected = IotHubPreconditionFailedException.class)
Expand Down

0 comments on commit 39d14a0

Please sign in to comment.