IBM / python-sdk-core

The python-sdk-core repository contains core functionality required by Python code generated by the IBM OpenAPI SDK Generator.
Apache License 2.0
20 stars 27 forks source link

Remove custom messaging in base_service.py #60

Closed ajaysikdar closed 3 years ago

ajaysikdar commented 4 years ago

The custom exception message in base_service.py does not give much control to the users when handling an exception at their side. It is a bit annoying for our customers too.

Though we are handling this exception our side, our customer is seeing exception logging msgs logged by base_service.py at lines https://github.com/IBM/python-sdk-core/blob/master/ibm_cloud_sdk_core/base_service.py#L227 https://github.com/IBM/python-sdk-core/blob/master/ibm_cloud_sdk_core/base_service.py#L230 https://github.com/IBM/python-sdk-core/blob/master/ibm_cloud_sdk_core/base_service.py#L233

Is it possible to remove these custom messages so that customers whoever is using this library, will be able to handle and log exception the way they want?

For example: We are getting this msg logged.

ERROR:root:Unknown error
Traceback (most recent call last):
  File "/Users/env/lib/python3.8/site-packages/ibm_cloud_sdk_core/base_service.py", line 224, in send
    raise ApiException(
ibm_cloud_sdk_core.api_exception.ApiException: Error: Unknown error, Code: 409

the response which we wants to show to our customer-

{'detail': 'Document already exists: xyz', 'instance': 'xyz', 'status': 409, 'title': 'Conflict', 'type': 'about:blank'}
mkistler commented 4 years ago

Maybe similar to the problem fixed in https://github.com/IBM/python-sdk-core/pull/59

rmkeezer commented 3 years ago

As pointed out, it seems that changes from https://github.com/IBM/python-sdk-core/pull/59 allows custom messages for non-401 errors so you should be able to specify the 409 error with your custom message now. @ajaykumar7-ibm does this solve your with the latest changes?

gilv commented 3 years ago

@rmkeezer do you plan to address this issue? We use latest sdk and suffer from those 500 error prints which are very annoying. I guess #59 didn't resolved it.. Please see this comment:

ibm_cloud_sdk_core lib always prints this minimum exception:

Traceback (most recent call last):
  File "/home/lachlan/miniconda3/envs/sm38/lib/python3.8/site-packages/ibm_cloud_sdk_core/base_service.py", line 246, in send
    raise ApiException(
ibm_cloud_sdk_core.api_exception.ApiException: Error: Internal server error, Code: 500

This is caused by this line. I don't know why, but they use the base logging lib to print the exception (in root logging) and then they call raise

except ApiException as err:
    logging.exception(err.message)
    raise

instead of simply do this:

except ApiException as err:
    raise err
padamstx commented 3 years ago

59 addressed a different issue... one where the error message included in the ApiException resulting from a 401 error was hard-coded by the BaseService.send() method. #59 fixed that issue by only including a core-supplied error message if a suitable error message could not be retrieved from the error response body.

This issue, on the other hand, is reporting that exceptions are being LOGGED to the console and this is problematic since some applications might not want or need that.

padamstx commented 3 years ago

This is addressed in https://github.com/IBM/python-sdk-core/pull/104

ibm-devx-automation commented 3 years ago

:tada: This issue has been resolved in version 3.5.1 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: