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: it is better to return the error with c.Error #61

Merged
merged 1 commit into from
Oct 27, 2021

Conversation

aermolaev
Copy link
Contributor

@aermolaev aermolaev commented Oct 27, 2021

Describe the PR
If there is an error reading the doc.json file, then a 500 status code and context as plain/text is returned without any error information.

% curl -vs http://localhost:8080/api/swagger/doc.json
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> GET /api/swagger/doc.json HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 500 Internal Server Error
< Content-Type: text/plain; charset=utf-8
< X-Content-Type-Options: nosniff
< Date: Wed, 27 Oct 2021 12:10:47 GMT
< Transfer-Encoding: chunked
<
Internal Server Error

it is better to return the error using c.Error:

% curl -vs http://localhost:8080/api/swagger/doc.json
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> GET /api/swagger/doc.json HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 500 Internal Server Error
< Content-Type: application/json; charset=utf-8
< Date: Wed, 27 Oct 2021 12:11:07 GMT
< Transfer-Encoding: chunked
<
{"error":"not yet registered swag"}

@codecov
Copy link

codecov bot commented Oct 27, 2021

Codecov Report

Merging #61 (83399cd) into master (f298ba3) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master       #61   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines           57        57           
=========================================
  Hits            57        57           
Impacted Files Coverage Δ
swagger.go 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f298ba3...83399cd. Read the comment docs.

Copy link
Contributor

@ubogdan ubogdan left a comment

Choose a reason for hiding this comment

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

LGTM

@ubogdan
Copy link
Contributor

ubogdan commented Oct 27, 2021

@aermolaev Thanks for your contribution.

@ubogdan ubogdan merged commit c2972cd into swaggo:master Oct 27, 2021
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.

None yet

2 participants