From 07319c484486d90987ea97f276464d71914ade49 Mon Sep 17 00:00:00 2001 From: cipchk Date: Tue, 13 Mar 2018 15:57:30 +0800 Subject: [PATCH] fix(abc:down-file): fix don't verify http status code, close #44 --- src/core/abc/down-file/down-file.directive.ts | 2 +- src/core/abc/down-file/down-file.spec.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/core/abc/down-file/down-file.directive.ts b/src/core/abc/down-file/down-file.directive.ts index 5b08f01c75..24d9c9cef8 100644 --- a/src/core/abc/down-file/down-file.directive.ts +++ b/src/core/abc/down-file/down-file.directive.ts @@ -36,7 +36,7 @@ export class DownFileDirective { responseType: 'blob', observe: 'response' }).subscribe((res: HttpResponse) => { - if (res.body.size <= 0) { + if (res.status !== 200 || res.body.size <= 0) { this.error.emit(res); return; } diff --git a/src/core/abc/down-file/down-file.spec.ts b/src/core/abc/down-file/down-file.spec.ts index 25ad1f56ff..96d53131aa 100644 --- a/src/core/abc/down-file/down-file.spec.ts +++ b/src/core/abc/down-file/down-file.spec.ts @@ -101,6 +101,19 @@ describe('abc: down-file', () => { ret.flush(genFile('docx', false)); expect(context.error).toHaveBeenCalled(); }); + + it('should be throw error when http status is not 200', () => { + spyOn(fs, 'saveAs'); + spyOn(context, 'error'); + expect(context.error).not.toHaveBeenCalled(); + expect(fs.saveAs).not.toHaveBeenCalled(); + (dl.query(By.css('#down-docx')).nativeElement as HTMLButtonElement).click(); + const ret = httpBed + .expectOne(req => req.url.startsWith('/')) as TestRequest; + ret.flush(null, { status: 201, statusText: '201' }); + expect(fs.saveAs).not.toHaveBeenCalled(); + expect(context.error).toHaveBeenCalled(); + }); }); @Component({