Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Commit dc767eb

Browse files
author
Ramón Tomás
committed
Fixed issue header not included in requests
Fixed issue httpclient returned response
1 parent c907155 commit dc767eb

File tree

9 files changed

+3526
-81
lines changed

9 files changed

+3526
-81
lines changed

src/Web/WebMVC/wwwroot/js/site.js

Lines changed: 3444 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Web/WebMVC/wwwroot/js/site.min.js

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Web/WebSPA/Client/modules/basket/basket.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class BasketService {
8181
if (response.status === 204) {
8282
return null;
8383
}
84-
return response.json();
84+
return response;
8585
}));
8686
}
8787

src/Web/WebSPA/Client/modules/campaigns/campaigns.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ export class CampaignsService {
3333
url = url + '?pageIndex=' + pageIndex + '&pageSize=' + pageSize;
3434

3535
return this.service.get(url).pipe(map((response: Response) => {
36-
return response.json();
36+
return response;
3737
}));
3838
}
3939

4040
getCampaign(id: number): Observable<ICampaignItem> {
4141
let url = this.marketingUrl + '/api/v1/m/campaigns/' + id;
4242

4343
return this.service.get(url).pipe(map((response: Response) => {
44-
return response.json();
44+
return response;
4545
}));
4646
}
4747
}

src/Web/WebSPA/Client/modules/orders/orders.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ export class OrdersService {
2828
let url = this.ordersUrl + '/api/v1/o/orders';
2929

3030
return this.service.get(url).pipe(map((response: Response) => {
31-
return response.json();
31+
return response;
3232
}));
3333
}
3434

3535
getOrder(id: number): Observable<IOrderDetail> {
3636
let url = this.ordersUrl + '/api/v1/o/orders/' + id;
3737

3838
return this.service.get(url).pipe(map((response: Response) => {
39-
return response.json();
39+
return response;
4040
}));
4141
}
4242

src/Web/WebSPA/Client/modules/shared/services/configuration.service.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Injectable } from '@angular/core';
2-
import { Http, Response, RequestOptionsArgs, RequestMethod, Headers } from '@angular/http';
1+
import { Injectable } from '@angular/core';
2+
import { HttpClient, HttpHeaders, HttpErrorResponse } from "@angular/common/http";
33
import { IConfiguration } from '../models/configuration.model';
44
import { StorageService } from './storage.service';
55

@@ -13,14 +13,14 @@ export class ConfigurationService {
1313
settingsLoaded$ = this.settingsLoadedSource.asObservable();
1414
isReady: boolean = false;
1515

16-
constructor(private http: Http, private storageService: StorageService) { }
16+
constructor(private http: HttpClient, private storageService: StorageService) { }
1717

1818
load() {
1919
const baseURI = document.baseURI.endsWith('/') ? document.baseURI : `${document.baseURI}/`;
2020
let url = `${baseURI}Home/Configuration`;
21-
this.http.get(url).subscribe((response: Response) => {
21+
this.http.get(url).subscribe((response) => {
2222
console.log('server settings loaded');
23-
this.serverSettings = response.json();
23+
this.serverSettings = response as IConfiguration;
2424
console.log(this.serverSettings);
2525
this.storageService.store('identityUrl', this.serverSettings.identityUrl);
2626
this.storageService.store('marketingUrl', this.serverSettings.marketingUrl);

src/Web/WebSPA/Client/modules/shared/services/data.service.ts

Lines changed: 35 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@ export class DataService {
1414
constructor(private http: HttpClient, private securityService: SecurityService) { }
1515

1616
get(url: string, params?: any): Observable<Response> {
17-
let options = {};
18-
19-
if (this.securityService) {
20-
options["headers"] = new HttpHeaders();
21-
options["headers"].append('Authorization', 'Bearer ' + this.securityService.GetToken());
22-
}
23-
17+
let options = { };
18+
this.setHeaders(options);
19+
2420
return this.http.get(url, options)
2521
.pipe(
2622
// retry(3), // retry a failed request up to 3 times
@@ -44,16 +40,8 @@ export class DataService {
4440
}
4541

4642
private doPost(url: string, data: any, needId: boolean, params?: any): Observable<Response> {
47-
let options = {};
48-
49-
options["headers"] = new HttpHeaders();
50-
if (this.securityService) {
51-
options["headers"].append('Authorization', 'Bearer ' + this.securityService.GetToken());
52-
}
53-
if (needId) {
54-
let guid = Guid.newGuid();
55-
options["headers"].append('x-requestid', guid);
56-
}
43+
let options = { };
44+
this.setHeaders(options, needId);
5745

5846
return this.http.post(url, data, options)
5947
.pipe(
@@ -63,35 +51,10 @@ export class DataService {
6351
catchError(this.handleError)
6452
);
6553
}
66-
67-
private doPut(url: string, data: any, needId: boolean, params?: any): Observable<Response> {
68-
let options = {};
69-
70-
options["headers"] = new HttpHeaders();
71-
if (this.securityService) {
72-
options["headers"].append('Authorization', 'Bearer ' + this.securityService.GetToken());
73-
}
74-
if (needId) {
75-
let guid = Guid.newGuid();
76-
options["headers"].append('x-requestid', guid);
77-
}
78-
79-
return this.http.put(url, data, options)
80-
.pipe(
81-
map((res: Response) => {
82-
return res;
83-
}),
84-
catchError(this.handleError)
85-
);
86-
}
87-
54+
8855
delete(url: string, params?: any) {
89-
let options = {};
90-
91-
if (this.securityService) {
92-
options["headers"] = new HttpHeaders();
93-
options["headers"].append('Authorization', 'Bearer ' + this.securityService.GetToken());
94-
}
56+
let options = { };
57+
this.setHeaders(options);
9558

9659
console.log('data.service deleting');
9760

@@ -103,17 +66,42 @@ export class DataService {
10366
private handleError(error: any) {
10467
if (error.error instanceof ErrorEvent) {
10568
// A client-side or network error occurred. Handle it accordingly.
106-
console.error('Client side network error occurred:', error.message);
69+
console.error('Client side network error occurred:', error.error.message);
10770
} else {
10871
// The backend returned an unsuccessful response code.
10972
// The response body may contain clues as to what went wrong,
11073
console.error('Backend - ' +
11174
`status: ${error.status}, ` +
11275
`statusText: ${error.statusText}, ` +
113-
`message: ${error.message}`);
76+
`message: ${error.error.message}`);
11477
}
11578

11679
// return an observable with a user-facing error message
11780
return throwError(error || 'server error');
11881
}
82+
83+
private doPut(url: string, data: any, needId: boolean, params?: any): Observable<Response> {
84+
let options = { };
85+
this.setHeaders(options, needId);
86+
87+
return this.http.put(url, data, options)
88+
.pipe(
89+
map((res: Response) => {
90+
return res;
91+
}),
92+
catchError(this.handleError)
93+
);
94+
}
95+
96+
private setHeaders(options: any, needId?: boolean){
97+
if (needId && this.securityService) {
98+
options["headers"] = new HttpHeaders()
99+
.append('authorization', 'Bearer ' + this.securityService.GetToken())
100+
.append('x-requestid', Guid.newGuid());
101+
}
102+
else if (this.securityService) {
103+
options["headers"] = new HttpHeaders()
104+
.append('authorization', 'Bearer ' + this.securityService.GetToken());
105+
}
106+
}
119107
}

src/Web/WebSPA/WebSPA.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,7 @@
175175
</ItemGroup>
176176

177177
<ProjectExtensions>
178-
<VisualStudio>
179-
<UserProperties package-lock_1json__JSONSchema="http://json.schemastore.org/bower" />
180-
</VisualStudio>
178+
<VisualStudio><UserProperties package-lock_1json__JSONSchema="http://json.schemastore.org/bower" package_1json__JSONSchema="http://json.schemastore.org/project-1.0.0-beta4" /></VisualStudio>
181179
</ProjectExtensions>
182180

183181
</Project>

src/Web/WebSPA/package-lock.json

Lines changed: 7 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)