R2Northstar / NorthstarMasterServer

Master server for Northstar
MIT License
92 stars 33 forks source link

Return status and header on HTTP error #86

Closed GeckoEidechse closed 2 years ago

GeckoEidechse commented 2 years ago

When performing an HTTP request, this returns the status code and headers of the response to help with figuring out why the request failed.

Mainly needed for #84 to check the response of the API in case of failure to check for ratelimit info etc.

Usage example

try
{
    authServerResponse = await asyncHttp.request( {
        method: "GET",
        host: "example.com",
        port: 80,
        path: "/example"
    } )
}
catch (response_object)
{
    console.log(response_object)
}

Gives on error

{
  statusCode: 200,
  headers: {
    date: 'Tue, 09 Aug 2022 21:39:23 GMT',
    'content-type': 'application/json; charset=utf-8',
    'content-length': '41',
    'access-control-allow-origin': '*',
    'example-rate-limit-remaining': '42'
  }
}

Currently existing functions do not try to reference this object so should not break existing calls to asyncHttp.request() in case of HTTP error.

barnabwhy commented 2 years ago

seems fine to me

Alystrasz commented 2 years ago

For now, we only need to access status/headers when request fails, this PR answer the need. LGTM

GeckoEidechse commented 2 years ago

provided it has been tested in some capacity

I guess you found the issue :3

ASpoonPlaysGames commented 2 years ago

provided it has been tested in some capacity

I guess you found the issue :3

Testing MS PRs :|

GeckoEidechse commented 2 years ago

Bob said looks fine, time to test in prod :trollface: