Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Use HttpError class when rejecting promises
Fixes #3872
  • Loading branch information
simhnna committed Sep 12, 2019
commit 2bb71d2097b1978c4796ace29fe401addfe2404a
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,12 @@ import { {{ classname }} } from './{{ classFilename }}';
export * from './{{ classFilename }}Interface'
{{/withInterfaces}}
{{/apis}}
import http = require('http');
export class HttpError extends Error {
constructor (public response: http.{{#supportsES6}}IncomingMessage{{/supportsES6}}{{^supportsES6}}ClientResponse{{/supportsES6}}, public body: any, public statusCode?: number) {
super('HTTP request failed');
this.name = 'HttpError';
}
}
export const APIS = [{{#apis}}{{#operations}}{{ classname }}{{/operations}}{{^-last}}, {{/-last}}{{/apis}}];
{{/apiInfo}}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { OAuth } from '../model/models';
{{/authMethods}}
{{/hasAuthMethods}}

import { HttpError } from './apis';

let defaultBasePath = '{{{basePath}}}';

// ===============================================
Expand Down Expand Up @@ -222,7 +224,7 @@ export class {{classname}} {
if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) {
resolve({ response: response, body: body });
} else {
reject({ response: response, body: body });
reject(new HttpError(response, body, response.statusCode));
}
}
});
Expand Down