fixed generic data source service

This commit is contained in:
David Lebee 2021-03-18 12:36:01 -04:00
parent 151e64786b
commit 5fae118850
2 changed files with 12 additions and 11 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@poweredsoft/ngx-data", "name": "@poweredsoft/ngx-data",
"version": "0.0.17", "version": "0.0.18",
"peerDependencies": { "peerDependencies": {
"@angular/common": "^8.2.4", "@angular/common": "^8.2.4",
"@angular/core": "^8.2.4", "@angular/core": "^8.2.4",

View File

@ -17,16 +17,22 @@ export class GenericRestDataSourceService
} }
private _handleErrorPipe(err: HttpErrorResponse) : Observable<IDataSourceError> { private _handleErrorPipe(err: HttpErrorResponse) : Observable<IDataSourceError> {
//console.log(typeof(err.error), err);
if (err.status == 500) { if (err.status == 500) {
return throwError(<IDataSourceErrorMessage>{ return throwError(<IDataSourceErrorMessage>{
type: 'message', type: 'message',
message: 'An unexpected error has occured' message: 'UNEXPECTED_ERROR_MESSAGE'
}); });
} }
if (typeof(err.error) == "object") { if (err.status == 400)
{
if (err.error && err.error.errors)
return throwError(<IDataSourceValidationError>{
type: 'validation',
errors: err.error.errors
});
// if status not okay then its an exception error // if status not okay then its an exception error
if (err.error.hasOwnProperty('Message') && typeof(err.error['Message']) == "string") { if (err.error.hasOwnProperty('Message') && typeof(err.error['Message']) == "string") {
return throwError(<IDataSourceErrorMessage>{ return throwError(<IDataSourceErrorMessage>{
@ -34,11 +40,6 @@ export class GenericRestDataSourceService
message: err.error['Message'] message: err.error['Message']
}); });
} }
return throwError(<IDataSourceValidationError>{
type: 'validation',
errors: err.error
});
} }
// general error message // general error message
@ -51,7 +52,7 @@ export class GenericRestDataSourceService
return throwError(<IDataSourceErrorMessage>{ return throwError(<IDataSourceErrorMessage>{
type: 'message', type: 'message',
message: 'An unexpected error has occured' message: 'UNEXPECTED_ERROR_MESSAGE'
}); });
} }