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

Fix user not found state status #638

Merged
merged 1 commit into from
Aug 28, 2024
Merged

Conversation

bobbyiliev
Copy link
Contributor

Fixes #637

│ Error: HTTP request error: status 404, response: 
│ 
│   with materialize_user.example_user,
│   on main.tf in resource "materialize_user" "example_user":
│  167: resource "materialize_user" "example_user" {

@bobbyiliev bobbyiliev requested a review from a team as a code owner August 28, 2024 09:13
@bobbyiliev bobbyiliev requested review from arusahni and removed request for a team August 28, 2024 09:13
Copy link
Contributor

@arusahni arusahni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My feedback is more of a nice-to-have than something that should be a blocker in getting this bugfix out.

Comment on lines +126 to +127
if strings.Contains(err.Error(), "404") || strings.Contains(strings.ToLower(err.Error()), "not found") {
// User doesn't exist, remove from state
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Digging into the Frontegg helpers, it seems as if we juggling this a few ways:

  1. ReadUser calls doRequest, which returns nil, fmt.Errorf(...) for 404 errors.
  2. Since err != nil, we immediately return that same result from ReadUser
  3. Further along in ReadUser (after we've early-returned out), we invoke an API error handler for non-200 status codes and return a string with different formatting from the Frontegg helper in step 1.

Ideally we can consolidate this string formatting to be consistent across endpoints, or even include a status code (by using an Error struct).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch @arusahni! Thank you for this!

I've created a tracking issue for this: #641

@bobbyiliev bobbyiliev merged commit 41af330 into main Aug 28, 2024
4 checks passed
@bobbyiliev bobbyiliev deleted the user-resource-404-not-found branch August 28, 2024 13:56
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.

materialize_user resource fails with 404 error if manually deleted
2 participants