octokit / request.js

Send parameterized requests to GitHub’s APIs with sensible defaults in browsers and Node
MIT License
232 stars 60 forks source link

[BUG]: Network Errors have statusCode 500 #713

Open Uzlopak opened 4 months ago

Uzlopak commented 4 months ago

What happened?

When there are network errors, the status code is 500. I think it would be better to set the status code to 0 indicating that the request has errored not because of some dubious internal server error on the remote, but because of some network issue

I think we should then increment the version by a major.

Versions

v. 9.1.1

Relevant log output

No response

Code of Conduct

github-actions[bot] commented 4 months ago

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

austinpray-mixpanel commented 4 weeks ago

Is there a good way to tell these network 500s from legit 500s on the current version? I'm trying to debug some 500 errors that come back as: "Error: Unhandled error: HttpError: Unexpected end of JSON input". This is in a github actions environment using https://github.com/actions/github-script 7.0.1

POST /repos/mixpanel/<snip>/merges - 500 in 4122ms
RequestError [HttpError]: Unexpected end of JSON input
    at /home/runner/work/_actions/actions/github-script/v7/dist/index.js:9561:11
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Error: Unhandled error: HttpError: Unexpected end of JSON input
    at async eval (eval at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v7/dist/index.js:35424:16), <anonymous>:34:25)
    at async main (/home/runner/work/_actions/actions/github-script/v7/dist/index.js:35522:20) {
  status: 500,
  request: {
    method: 'POST',
    url: 'https://api.github.com/repos/mixpanel/<snip>/merges',
    headers: {
      accept: 'application/vnd.github.v3+json',
      'user-agent': 'actions/github-script octokit-core.js/5.0.1 Node.js/20.13.1 (linux; x64)',
      authorization: 'token [REDACTED]',
      'content-type': 'application/json; charset=utf-8'
    },
    body: '{"base":"rc-241101-austin-debug-create-release-candidate-1b90","head":"austin-debug-create-release-candidate","commit_message":"RC: austin-debug-create-release-candidate"}',
    request: {
      agent: [Agent],
      fetch: [Function: proxyFetch],
      hook: [Function: bound bound register]
    }
  }
}

This same request works just fine on curl from my dev machine. Makes me think there is some kind of network issue but the 500 error status code is throwing me for a loop