Skip to content

fix: store raw response in APIError during JSON parsing #294

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

neilmartin83
Copy link

Change

Thank you for your contribution !
Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context.
List any dependencies that are required for this change.

Type of Change

Been meaning to dig into this one for a while... :-) When working with endpoints that give JSON responses, raw_response was being returned as an empty string, for example:

jamfpro_sso_settings.okta: Modifying... [id=jamfpro_sso_settings_singleton]
jamfpro_sso_settings.okta: Still modifying... [id=jamfpro_sso_settings_singleton, 00m10s elapsed]
╷
│ Error: failed to update SSO settings: failed to update sso settings, error: {"status_code":400,"method":"PUT","url":"https://ajksxfz.fleet.jamf.build/api/v3/sso","message":"API Error Response","raw_response":""}

This change just makes sure we always output the raw response. I think it fails because the APIError struct does not match the fields we get from a Jamf Pro JSON error response. But I didn't want to change that in case it breaks response handling from other APIs this client is used with.

Now a TF error looks like this instead (populated raw_response field) which is extremely helpful for debugging/troubleshooting provider/API/TF module issues downstream:

│ Error: failed to update SSO settings: failed to update sso settings, error: {"status_code":400,"method":"PUT","url":"https://ajksxfz.fleet.jamf.build/api/v3/sso","message":"API Error Response","raw_response":"{\n  \"httpStatus\" : 400,\n  \"errors\" : [ {\n    \"code\" : \"INVALID_METADATA\",\n    \"description\" : \"Unable to unmarshall metadata\",\n    \"id\" : null,\n    \"field\" : \"idpUrl\"\n  } ]\n}"}

Please DELETE options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update (Wiki)
  • Refactor (refactoring code, removing code, changing code structure)

Checklist

  • I'm sure there are no other open Pull Requests for the same update/change
  • My corresponding pipelines / checks run clean and green without any errors or warnings
  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (readme)
  • I did format my code

@neilmartin83 neilmartin83 requested a review from ShocOne as a code owner July 31, 2025 21:24
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

Successfully merging this pull request may close these issues.

1 participant