square / square-java-sdk

Java client library for the Square API
https://developer.squareup.com
Other
59 stars 29 forks source link

Better exception message from ApiException #39

Open finci-square opened 3 years ago

finci-square commented 3 years ago

Non successful http responses yield an ApiException whose message is just "HTTP Response Not OK". This is very cryptic and quite frustrating if the developer hasn't written code to capture more information about the error. It would be much improved if we parse the error response body and give an exception message that includes details from the response.

sseaman commented 3 years ago

Thanks for reporting this. We're investigating ways to improve it.

finci-square commented 3 years ago

Ultimately all "Default*Api" classes call https://github.com/square/square-java-sdk/blob/65a992f0355ee404655170e00022cda2c71df01a/src/main/java/com/squareup/square/api/BaseApi.java validateResponse which news ApiException. The implementation of ApiException just needs to use the response if it has one and parse it earlier to pass to super

BryceBlankinship commented 11 months ago

any progress on this one? I keep running into unexplainable "HTTP Response Not OK" errors and I am just guessing as to what I need to fix. One of my http responses worked too... not sure why!

BryceBlankinship commented 11 months ago

@finci-square aha I found my issue and I think that'll find yours, make sure you are importing the right ApiException class! I was getting mine from a google package instead of squares, then following this documentation for error handling: https://developer.squareup.com/docs/sdks/java/using-java-sdk#handle-the-responses

finci-square commented 11 months ago

Square should consider renaming the class name

On Sat, Nov 11, 2023 at 1:30 PM Bryce Blankinship @.***> wrote:

@finci-square https://github.com/finci-square aha I found my issue and I think that'll find yours, make sure you are importing the right ApiException class! I was getting mine from a google package instead of squares, then following this documentation for error handling: https://developer.squareup.com/docs/sdks/java/using-java-sdk#handle-the-responses

— Reply to this email directly, view it on GitHub https://github.com/square/square-java-sdk/issues/39#issuecomment-1806885958, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANQHD2UECDKSB4FULA5P7FTYD674HAVCNFSM4WSECU22U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBQGY4DQNJZGU4A . You are receiving this because you were mentioned.Message ID: @.***>

AnkitPatel1404 commented 10 months ago

@BryceBlankinship @sseaman @finci-square I'm importing right class but still getting same error message. Any alternative solution can you suggest?

zenmasterjobo commented 10 months ago

@AnkitPatel1404

Which API are you calling that is returning this error?

@finci-square @BryceBlankinship I have notified our team that creates the SDKs about stripping away the error message. I will update when I have more information about the change. I have also asked that they consider changing the name of the class to prevent potential name conflicts.

BryceBlankinship commented 10 months ago

Awesome thanks

AnkitPatel1404 commented 10 months ago

Thanks for the response @zenmasterjobo, I'm using this API "paymentsApi.createPayment(body)"; and getting error message "HTTP Response Not OK".

zenmasterjobo commented 10 months ago

Thanks for the response @zenmasterjobo, I'm using this API "paymentsApi.createPayment(body)"; and getting error message "HTTP Response Not OK".

Hi @AnkitPatel1404 - if you can log into your developer dashboard and then click into your app, and then click API Logs in the left side navigation, you will be able to see some more details about the request your Java app made to Square. There should be a more clear error message logged there.

AnkitPatel1404 commented 10 months ago

@zenmasterjobo @finci-square, In square dashboard, I got response like this "errors": [ { "code": "GENERIC_DECLINE", "detail": "Authorization error: 'GENERIC_DECLINE'", "category": "PAYMENT_METHOD_ERROR" }

Unable to find exact cause of this error. Can you please help me on this?