Skip to content

Commit

Permalink
SHIBUI-925 Implemented fix for error messages on upload
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Dec 6, 2018
1 parent 5b9a841 commit 21265a4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
8 changes: 6 additions & 2 deletions ui/src/app/metadata/domain/service/resolver.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,19 @@ export class ResolverService {
return this.http.post<MetadataResolver>(`${this.base}${this.endpoint}`, xml, {
headers: new HttpHeaders().set('Content-Type', 'application/xml'),
params: new HttpParams().set('spName', name)
});
}).pipe(catchError(error => {
return throwError({ errorCode: error.status, errorMessage: `Unable to upload file ... ${error.error}` });
}));
}

createFromUrl(name: string, url: string): Observable<MetadataResolver> {
let body = `metadataUrl=${url}`;
return this.http.post<MetadataResolver>(`${this.base}${this.endpoint}`, body, {
headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded'),
params: new HttpParams().set('spName', name)
});
}).pipe(catchError(error => {
return throwError({ errorCode: error.status, errorMessage: `Unable to upload file ... ${error.error}` });
}));
}

preview(id: string): Observable<string> {
Expand Down
33 changes: 27 additions & 6 deletions ui/src/app/metadata/resolver/effect/collection.effects.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { Injectable } from '@angular/core';
import { Effect, Actions, ofType } from '@ngrx/effects';
import { Router } from '@angular/router';

import { Store } from '@ngrx/store';
import { of } from 'rxjs';
import { map, catchError, switchMap, tap } from 'rxjs/operators';
import { map, catchError, switchMap, tap, withLatestFrom } from 'rxjs/operators';

import * as providerActions from '../action/collection.action';
import * as draftActions from '../action/draft.action';
import { ResolverCollectionActionTypes } from '../action/collection.action';
import { ResolverService } from '../../domain/service/resolver.service';
import { removeNulls } from '../../../shared/util';
import { AddNotification } from '../../../notification/action/notification.action';
import { Notification, NotificationType } from '../../../notification/model/notification';
import { I18nService } from '../../../i18n/service/i18n.service';
import * as fromRoot from '../../../app.reducer';
import * as fromI18n from '../../../i18n/reducer';


/* istanbul ignore next */
@Injectable()
Expand Down Expand Up @@ -112,11 +118,24 @@ export class ResolverCollectionEffects {
ofType<providerActions.AddResolverSuccess>(ResolverCollectionActionTypes.ADD_RESOLVER_SUCCESS),
map(action => action.payload),
map(provider => {
console.log(provider);
return new draftActions.RemoveDraftRequest(provider);
})
);

@Effect()
addResolverFailNotification$ = this.actions$.pipe(
ofType<providerActions.AddResolverFail>(ResolverCollectionActionTypes.ADD_RESOLVER_FAIL),
map(action => action.payload),
withLatestFrom(this.store.select(fromI18n.getMessages)),
map(([error, messages]) => new AddNotification(
new Notification(
NotificationType.Danger,
`${error.errorCode}: ${this.i18nService.translate(error.errorMessage, null, messages)}`,
8000
)
))
);

@Effect()
uploadResolverRequest$ = this.actions$.pipe(
ofType<providerActions.UploadResolverRequest>(ResolverCollectionActionTypes.UPLOAD_RESOLVER_REQUEST),
Expand All @@ -126,7 +145,7 @@ export class ResolverCollectionEffects {
.upload(file.name, file.body)
.pipe(
map(p => new providerActions.AddResolverSuccess(p)),
catchError(() => of(new providerActions.AddResolverFail(file)))
catchError((error) => of(new providerActions.AddResolverFail(error)))
)
)
);
Expand All @@ -140,14 +159,16 @@ export class ResolverCollectionEffects {
.createFromUrl(file.name, file.url)
.pipe(
map(p => new providerActions.AddResolverSuccess(p)),
catchError(() => of(new providerActions.AddResolverFail(file)))
catchError((error) => of(new providerActions.AddResolverFail(error)))
)
)
);

constructor(
private descriptorService: ResolverService,
private actions$: Actions,
private router: Router
private router: Router,
private store: Store<fromRoot.State>,
private i18nService: I18nService
) { }
} /* istanbul ignore next */

0 comments on commit 21265a4

Please sign in to comment.