8000 fix(common): set HttpResponseBase.statusText to an empty string by default by kescherCode · Pull Request #57580 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content

fix(common): set HttpResponseBase.statusText to an empty string by default #57580

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 6 additions & 5 deletions packages/common/http/src/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export abstract class HttpResponseBase {
readonly status: number;

/**
* Textual description of response status code, defaults to OK.
* Textual description of response status code, defaults to an empty string.
*
* Do not depend on this.
*/
Expand Down Expand Up @@ -200,7 +200,7 @@ export abstract class HttpResponseBase {
url?: string;
},
defaultStatus: number = 200,
defaultStatusText: string = 'OK',
defaultStatusText: string = '',
) {
// If the hash has values passed, use them to initialize the response.
// Otherwise use the default values.
Expand Down Expand Up @@ -363,9 +363,10 @@ export class HttpErrorResponse extends HttpResponseBase implements Error {
if (this.status >= 200 && this.status < 300) {
this.message = `Http failure during parsing for ${init.url || '(unknown url)'}`;
} else {
this.message = `Http failure response for ${init.url || '(unknown url)'}: ${init.status} ${
init.statusText
}`;
const statusErrorText = [undefined, ''].includes(init.statusText)
? ''
: ` ${init.statusText}`;
this.message = `Http failure response for ${init.url || '(unknown url)'}: ${init.status}${statusErrorText}`;
}
this.error = init.error || null;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/common/http/src/xhr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class HttpXhrBackend implements HttpBackend {
return headerResponse;
}

const statusText = xhr.statusText || 'OK';
const statusText = xhr.statusText || '';

// Parse headers from XMLHttpRequest - this step is lazy.
const headers = new HttpHeaders(xhr.getAllResponseHeaders());
Expand Down
3 changes: 0 additions & 3 deletions packages/common/http/testing/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ export class TestRequest {
statusText ||= 'OK';
Copy link
Member

Choose a reason for hiding this comment

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

There's an OK here as well that may need to be audited.

}
}
if (statusText === undefined) {
throw new Error('statusText is required when setting a custom status.');
}
if (status >= 200 && status < 300) {
this.observer.next(new HttpResponse<any>({body, headers, status, statusText, url}));
this.observer.complete();
Expand Down
Loading
0