mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-03-21 17:25:10 -05:00
Net: Expose response data to consumers
Headers are useful for a couple of Net consumers (rate limit data, that sort of thing.)
This commit is contained in:
parent
c89c68ad3a
commit
4b79ee1276
|
|
@ -172,6 +172,8 @@ export class NetStream extends Streams.ReadWriteStream {
|
|||
}
|
||||
export class NetRequest {
|
||||
uri: string;
|
||||
/** Response from last request, made so response stuff is available without being hacky */
|
||||
response?: http.IncomingMessage;
|
||||
constructor(uri: string) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
|
@ -202,6 +204,7 @@ export class NetRequest {
|
|||
async get(opts: NetRequestOptions = {}): Promise<string> {
|
||||
const stream = this.getStream(opts);
|
||||
const response = await stream.response;
|
||||
if (response) this.response = response;
|
||||
if (response && response.statusCode !== 200) {
|
||||
throw new HttpError(response.statusMessage || "Connection error", response.statusCode, await stream.readAll());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user