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

Improve error message (rfc7807) #13680

Merged
merged 12 commits into from
Oct 31, 2022

Conversation

gcatanese
Copy link
Contributor

@antihax (2017/11) @grokify (2018/07) @kemokemo (2018/09) @jirikuncar (2021/01) @ph4r5h4d (2021/04)

Improve error message when error returns RFC7807 model
Fix #13679

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (6.1.0) (minor release - breaking changes with fallbacks), 7.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.


// status title (detail)
return fmt.Sprintf("%s %s", status, str)
}
Copy link
Member

@wing328 wing328 Oct 19, 2022

Choose a reason for hiding this comment

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

looks like this code block uses 4-space instead of tabs for indention, can you update it to use tabs instead?

@@ -360,7 +360,7 @@ func (a *{{{classname}}}Service) {{nickname}}Execute(r {{#structPrefix}}{{&class
error: localVarHTTPResponse.Status,
}
{{#responses}}
{{#dataType}}
{{#dataType}}
Copy link
Member

Choose a reason for hiding this comment

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

please use tabs instead of 4-space

@gcatanese
Copy link
Contributor Author

@wing328 It should be ok now, I had to remove the Mustache plugin for IntelliJ that was altering my indentation (sorry to waste your time)

@wing328 wing328 merged commit 1de28c8 into OpenAPITools:master Oct 31, 2022
@jmontroy90
Copy link

jmontroy90 commented Nov 3, 2022

@gcatanese This PR introduced a panic into our code because it was trying to parse our custom error response according to RFC7807. Our custom error response doesn't have a Title or Detail field, so both of those reflect-based lookups are invalid and the first one hit in the code path (Title) caused a panic. Can you take a look?

Specifically, can the code check to ensure that the given error response conforms to RFC7807 before it tries to extract out its fields?

@gcatanese
Copy link
Contributor Author

Hey @jmontroy90 I had a look and I cannot reproduce the problem. The formatErrorMessage checks if the field exists before extracting it

	metaValue := reflect.ValueOf(v).Elem()

	field := metaValue.FieldByName("Title")
	if field != (reflect.Value{}) {
		str = fmt.Sprintf("%s", field.Interface())
	}

Am I missing something?

@jmontroy90
Copy link

@gcatanese fair enough - I'll do some homework to reproduce and get back to you.

@thiagoarrais
Copy link
Contributor

thiagoarrais commented Apr 6, 2023

@jmontroy90: is your problem maybe related to #15147?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[REQ] [Go] Improved error message when model implements RFC7807
4 participants