gorocket icon indicating copy to clipboard operation
gorocket copied to clipboard

Improved error handling

Open OscarVanL opened this issue 2 years ago • 2 comments

Fixes my issue: https://github.com/badkaktus/gorocket/issues/13

  • Embeds an ErrStatus struct, which contains all of the Rocket.Chat error response fields that can be populated under different scenarios.

  • The error handling approach is inspired by how Rocket.Chat's Go SDK handles REST errors, but extended to handle a couple of extra error response fields I have come across and add informative error messages.

  • Adds an option WithDebug, which will also include the details field which is sometimes present in error responses. I didn't include this by default because you can get errors that could expose data in logs you didn't want to, like this for validation error's inputs:

{
        "errorType": "error-input-is-not-a-valid-field",
	"details": {
		"method": "insertOrUpdateUser",
		"input": "sdfsdf ;;; ; ; -- ; ; fsdf",
		"field": "Username"
	}
}
  • I also fixed up some function comments to be properly formatted Godoc docstrings.

  • This could be considered a breaking change if some consumers of this package want request errors to fail without returning an err, but as this is a v0 package we're fine to make breaking changes.

OscarVanL avatar Feb 18 '23 21:02 OscarVanL

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

github-actions[bot] avatar Apr 05 '23 02:04 github-actions[bot]

This PR was closed because it has been stalled for 10 days with no activity.

github-actions[bot] avatar Apr 15 '23 02:04 github-actions[bot]