andrusha / snowflake-rs

Snowflake API libraries for Rust
Apache License 2.0
31 stars 26 forks source link

First attempt at improved error handling #34

Open colin99d opened 8 months ago

colin99d commented 8 months ago

This pr adds a new Other enum item to AuthResponse, which allows us to capture any json, and display it. Output goes from:

AuthError(RequestError(RequestError(reqwest::Error { kind: Decode, source: Error("data did not match any variant of untagged enum AuthResponse", line: 0, column: 0) })))

To AuthError(UnexpectedResponse(Some(Object {"code": String("390186"), "data": Object {"age": Number(0), "errorCode": String("390186"), "internalError": Bool(false)}, "headers": Null, "message": String("Role 'ACCOUNTADMIN' specified in the connect string is not granted to this user. Contact your local system administrator, or attempt to login with another role, e.g. PUBLIC."), "success": Bool(false)})))

Which, in my opinion, is MUCH more actionable. True to my notes in the issue, I used the data received from the response to better implement the given error, and got the even cleaner response of: AuthError(AuthFailed("390186", "Role 'ACCOUNTADMIN' specified in the connect string is not granted to this user. Contact your local system administrator, or attempt to login with another role, e.g. PUBLIC."))

This PR is purposely left dirty. Please provide general feedback for me to implement, and tell me whether you like the general idea, and then I will go through and clean everything up.

Closes #31

colin99d commented 6 months ago

@andrusha any comments on this?