Azure / Azure/azure-iot-service-sdk-java

IotHubException subtypes should provide errorCode etc.

Open
#38 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
5
Forks
14
PR merge metrics
No merged PRs in 30d

Description

I'm trying to add good metrics to my application. Currently, I see that almost all subtypes from `IotHubException` do not provide any useful `ErrorCodeDescription` or `ErrorCode`; they only offer a `message` that I need to parse on my own to get the error code.

I would suggest creating the objects like they should get created (decompiled):
```java
private static IotHubException getIotHubException(String error, String errorDescription)
{
switch (error)
{
case IotHubUnauthorizedException.amqpErrorCode:
return new IotHubUnauthorizedException(errorDescription);
case IotHubNotFoundException.amqpErrorCode:
return new IotHubNotFoundException(errorDescription);
case IotHubDeviceMaximumQueueDepthExceededException.amqpErrorCode:
return new IotHubDeviceMaximumQueueDepthExceededException(errorDescription);
case IotHubMessageTooLargeException.amqpErrorCode:
return new IotHubMessageTooLargeException(errorDescription);
case IotHubInternalServerErrorException.amqpErrorCode:
return new IotHubInternalServerErrorException(errorDescription);
case IotHubInvalidOperationException.amqpErrorCode:
return new IotHubInvalidOperationException(errorDescription);
case IotHubNotSupportedException.amqpErrorCode:
return new IotHubNotSupportedException(errorDescription);
case IotHubPreconditionFailedException.amqpErrorCode:
return new IotHubPreconditionFailedException(errorDescription);
}

if (getNetworkException(error, errorDescription) == null)
{
// by default, must return at least the error code and description to the user
return new IotHubException(error + ":" + errorDescription);
}

return null;
}
```

That is the current implementation of the `ProtonJExceptionParser` which provides the given exceptions. As we can see, it only provides a `String` instead of a concrete error code, which leads to the behavior that the `IotHubException` is using the default error code `0` and the `ErrorCodeDescription.UnclassifiedErrorCode`

That is currently not quite nice for metrics. I would like to have that adjusted to be able to work with the given types in the SDK.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at ProtonJExceptionParser and inspect how it creates IotHubException subtypes, then compare those constructors with IotHubException's error-code fields. Done means the listed concrete exceptions expose their specific error codes and descriptions instead of default code 0 and UnclassifiedErrorCode, while unknown errors retain useful code and description information.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.