Fixed issue header not included in requests

Fixed issue httpclient returned response
This commit is contained in:
Ramón Tomás 2018-09-28 10:14:29 +02:00
parent c907155112
commit dc767eb51c
9 changed files with 3526 additions and 81 deletions

File diff suppressed because one or more lines are too long

29
src/Web/WebMVC/wwwroot/js/site.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -81,7 +81,7 @@ export class BasketService {
if (response.status === 204) {
return null;
}
return response.json();
return response;
}));
}

View File

@ -33,7 +33,7 @@ export class CampaignsService {
url = url + '?pageIndex=' + pageIndex + '&pageSize=' + pageSize;
return this.service.get(url).pipe(map((response: Response) => {
return response.json();
return response;
}));
}
@ -41,7 +41,7 @@ export class CampaignsService {
let url = this.marketingUrl + '/api/v1/m/campaigns/' + id;
return this.service.get(url).pipe(map((response: Response) => {
return response.json();
return response;
}));
}
}

View File

@ -28,7 +28,7 @@ export class OrdersService {
let url = this.ordersUrl + '/api/v1/o/orders';
return this.service.get(url).pipe(map((response: Response) => {
return response.json();
return response;
}));
}
@ -36,7 +36,7 @@ export class OrdersService {
let url = this.ordersUrl + '/api/v1/o/orders/' + id;
return this.service.get(url).pipe(map((response: Response) => {
return response.json();
return response;
}));
}

View File

@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { Http, Response, RequestOptionsArgs, RequestMethod, Headers } from '@angular/http';
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpErrorResponse } from "@angular/common/http";
import { IConfiguration } from '../models/configuration.model';
import { StorageService } from './storage.service';
@ -13,14 +13,14 @@ export class ConfigurationService {
settingsLoaded$ = this.settingsLoadedSource.asObservable();
isReady: boolean = false;
constructor(private http: Http, private storageService: StorageService) { }
constructor(private http: HttpClient, private storageService: StorageService) { }
load() {
const baseURI = document.baseURI.endsWith('/') ? document.baseURI : `${document.baseURI}/`;
let url = `${baseURI}Home/Configuration`;
this.http.get(url).subscribe((response: Response) => {
this.http.get(url).subscribe((response) => {
console.log('server settings loaded');
this.serverSettings = response.json();
this.serverSettings = response as IConfiguration;
console.log(this.serverSettings);
this.storageService.store('identityUrl', this.serverSettings.identityUrl);
this.storageService.store('marketingUrl', this.serverSettings.marketingUrl);

View File

@ -14,13 +14,9 @@ export class DataService {
constructor(private http: HttpClient, private securityService: SecurityService) { }
get(url: string, params?: any): Observable<Response> {
let options = {};
if (this.securityService) {
options["headers"] = new HttpHeaders();
options["headers"].append('Authorization', 'Bearer ' + this.securityService.GetToken());
}
let options = { };
this.setHeaders(options);
return this.http.get(url, options)
.pipe(
// retry(3), // retry a failed request up to 3 times
@ -44,16 +40,8 @@ export class DataService {
}
private doPost(url: string, data: any, needId: boolean, params?: any): Observable<Response> {
let options = {};
options["headers"] = new HttpHeaders();
if (this.securityService) {
options["headers"].append('Authorization', 'Bearer ' + this.securityService.GetToken());
}
if (needId) {
let guid = Guid.newGuid();
options["headers"].append('x-requestid', guid);
}
let options = { };
this.setHeaders(options, needId);
return this.http.post(url, data, options)
.pipe(
@ -63,35 +51,10 @@ export class DataService {
catchError(this.handleError)
);
}
private doPut(url: string, data: any, needId: boolean, params?: any): Observable<Response> {
let options = {};
options["headers"] = new HttpHeaders();
if (this.securityService) {
options["headers"].append('Authorization', 'Bearer ' + this.securityService.GetToken());
}
if (needId) {
let guid = Guid.newGuid();
options["headers"].append('x-requestid', guid);
}
return this.http.put(url, data, options)
.pipe(
map((res: Response) => {
return res;
}),
catchError(this.handleError)
);
}
delete(url: string, params?: any) {
let options = {};
if (this.securityService) {
options["headers"] = new HttpHeaders();
options["headers"].append('Authorization', 'Bearer ' + this.securityService.GetToken());
}
let options = { };
this.setHeaders(options);
console.log('data.service deleting');
@ -103,17 +66,42 @@ export class DataService {
private handleError(error: any) {
if (error.error instanceof ErrorEvent) {
// A client-side or network error occurred. Handle it accordingly.
console.error('Client side network error occurred:', error.message);
console.error('Client side network error occurred:', error.error.message);
} else {
// The backend returned an unsuccessful response code.
// The response body may contain clues as to what went wrong,
console.error('Backend - ' +
`status: ${error.status}, ` +
`statusText: ${error.statusText}, ` +
`message: ${error.message}`);
`message: ${error.error.message}`);
}
// return an observable with a user-facing error message
return throwError(error || 'server error');
}
private doPut(url: string, data: any, needId: boolean, params?: any): Observable<Response> {
let options = { };
this.setHeaders(options, needId);
return this.http.put(url, data, options)
.pipe(
map((res: Response) => {
return res;
}),
catchError(this.handleError)
);
}
private setHeaders(options: any, needId?: boolean){
if (needId && this.securityService) {
options["headers"] = new HttpHeaders()
.append('authorization', 'Bearer ' + this.securityService.GetToken())
.append('x-requestid', Guid.newGuid());
}
else if (this.securityService) {
options["headers"] = new HttpHeaders()
.append('authorization', 'Bearer ' + this.securityService.GetToken());
}
}
}

View File

@ -175,9 +175,7 @@
</ItemGroup>
<ProjectExtensions>
<VisualStudio>
<UserProperties package-lock_1json__JSONSchema="http://json.schemastore.org/bower" />
</VisualStudio>
<VisualStudio><UserProperties package-lock_1json__JSONSchema="http://json.schemastore.org/bower" package_1json__JSONSchema="http://json.schemastore.org/project-1.0.0-beta4" /></VisualStudio>
</ProjectExtensions>
</Project>

View File

@ -3877,13 +3877,11 @@
},
"balanced-match": {
"version": "1.0.0",
"bundled": true,
"optional": true
"bundled": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@ -3896,18 +3894,15 @@
},
"code-point-at": {
"version": "1.1.0",
"bundled": true,
"optional": true
"bundled": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true,
"optional": true
"bundled": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"optional": true
"bundled": true
},
"core-util-is": {
"version": "1.0.2",
@ -4010,8 +4005,7 @@
},
"inherits": {
"version": "2.0.3",
"bundled": true,
"optional": true
"bundled": true
},
"ini": {
"version": "1.3.5",
@ -4021,7 +4015,6 @@
"is-fullwidth-code-point": {
"version": "1.0.0",
"bundled": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@ -4034,20 +4027,17 @@
"minimatch": {
"version": "3.0.4",
"bundled": true,
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
},
"minimist": {
"version": "0.0.8",
"bundled": true,
"optional": true
"bundled": true
},
"minipass": {
"version": "2.2.4",
"bundled": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.1",
"yallist": "^3.0.0"
@ -4064,7 +4054,6 @@
"mkdirp": {
"version": "0.5.1",
"bundled": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
@ -4137,8 +4126,7 @@
},
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
"optional": true
"bundled": true
},
"object-assign": {
"version": "4.1.1",
@ -4148,7 +4136,6 @@
"once": {
"version": "1.4.0",
"bundled": true,
"optional": true,
"requires": {
"wrappy": "1"
}
@ -4254,7 +4241,6 @@
"string-width": {
"version": "1.0.2",
"bundled": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",