Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidRequestException - handling specific fields #20

Open
ecollis6 opened this issue Jul 24, 2019 · 1 comment
Open

InvalidRequestException - handling specific fields #20

ecollis6 opened this issue Jul 24, 2019 · 1 comment
Assignees

Comments

@ecollis6
Copy link

Hey, I noticed an issue while I was trying to gracefully handle coupon errors. From what I can tell, there is not a good way to programmatically handle errors for specific fields. According to the documentation, I should be able to use the Param field on InvalidRequestException to determine the incorrect parameter, but from my experience, it has always been null. In the meantime, I am using ApiCode, however, it is deprecated.

-		(ApiException) e	{"Coupon INVALID_COUPON_TEST cannot be applied as it is not applicable to any of the items"}	ChargeBee.Api.ApiException {ChargeBee.Exceptions.InvalidRequestException}
		ApiCode	"coupon_not_applicable"	string
		ApiErrorCode	"invalid_request"	string
		ApiMessage	"Coupon INVALID_COUPON_TEST cannot be applied as it is not applicable to any of the items"	string
+		Data	{System.Collections.ListDictionaryInternal}	System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
		HResult	-2146233088	int
		HelpLink	null	string
		HttpCode	BadRequest	System.Net.HttpStatusCode
		HttpStatusCode	BadRequest	System.Net.HttpStatusCode
+		InnerException	null	System.Exception
		Message	"Coupon INVALID_COUPON_TEST cannot be applied as it is not applicable to any of the items"	string
		Param	null	string
		Parameter	null	string
		Source	"ChargeBee"	string
+		TargetSite	{Void HandleException(System.Net.Http.HttpResponseMessage)}	System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
		Type	"invalid_request"	string
+		Static members		
+		Non-Public members		
@cb-rakesh cb-rakesh self-assigned this Aug 19, 2021
@cb-alish
Copy link
Collaborator

Hi @ecollis6 , I'm sorry about the delay in responding to this. Not all api error will have param field in the response. Please refer to Error Attribute section in the documentation. For those error with param in the response, we’ll be able to access it in the following way.

catch (ApiException error)
        {
            Console.WriteLine($"Error: {error.Param}");
        } 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants