Skip to content

Commit 6d582cd

Browse files
authored
Merge pull request DSpace#2816 from atmire/w2p-111326_fix-status-code-object-not-found-7.4
Return 404 Not Found status code on missing identifiers
2 parents a4387bb + b48db7d commit 6d582cd

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/app/lookup-by-id/objectnotfound/objectnotfound.component.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
import { ActivatedRoute } from '@angular/router';
88
import { TranslateModule } from '@ngx-translate/core';
99
import { of as observableOf } from 'rxjs';
10+
import { ServerResponseService } from 'src/app/core/services/server-response.service';
1011

1112
import { ActivatedRouteStub } from '../../shared/testing/active-router.stub';
1213
import { ObjectNotFoundComponent } from './objectnotfound.component';
@@ -21,6 +22,10 @@ describe('ObjectNotFoundComponent', () => {
2122
const activatedRouteStub = Object.assign(new ActivatedRouteStub(), {
2223
params: observableOf({ id: testUUID, idType: uuidType }),
2324
});
25+
const serverResponseServiceStub = jasmine.createSpyObj('ServerResponseService', {
26+
setNotFound: jasmine.createSpy('setNotFound'),
27+
});
28+
2429
const activatedRouteStubHandle = Object.assign(new ActivatedRouteStub(), {
2530
params: observableOf({ id: handleId, idType: handlePrefix }),
2631
});
@@ -31,6 +36,7 @@ describe('ObjectNotFoundComponent', () => {
3136
TranslateModule.forRoot(),
3237
ObjectNotFoundComponent,
3338
], providers: [
39+
{ provide: ServerResponseService, useValue: serverResponseServiceStub } ,
3440
{ provide: ActivatedRoute, useValue: activatedRouteStub },
3541
],
3642
schemas: [NO_ERRORS_SCHEMA],
@@ -52,6 +58,10 @@ describe('ObjectNotFoundComponent', () => {
5258
expect(comp.idType).toEqual(uuidType);
5359
expect(comp.missingItem).toEqual('uuid: ' + testUUID);
5460
});
61+
62+
it('should call serverResponseService.setNotFound', () => {
63+
expect(serverResponseServiceStub.setNotFound).toHaveBeenCalled();
64+
});
5565
});
5666

5767
describe( 'legacy handle request', () => {
@@ -61,6 +71,7 @@ describe('ObjectNotFoundComponent', () => {
6171
TranslateModule.forRoot(),
6272
ObjectNotFoundComponent,
6373
], providers: [
74+
{ provide: ServerResponseService, useValue: serverResponseServiceStub },
6475
{ provide: ActivatedRoute, useValue: activatedRouteStubHandle },
6576
],
6677
schemas: [NO_ERRORS_SCHEMA],
@@ -78,6 +89,10 @@ describe('ObjectNotFoundComponent', () => {
7889
expect(comp.idType).toEqual(handlePrefix);
7990
expect(comp.missingItem).toEqual('handle: ' + handlePrefix + '/' + handleId);
8091
});
92+
93+
it('should call serverResponseService.setNotFound', () => {
94+
expect(serverResponseServiceStub.setNotFound).toHaveBeenCalled();
95+
});
8196
});
8297

8398
});

src/app/lookup-by-id/objectnotfound/objectnotfound.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
RouterLink,
1010
} from '@angular/router';
1111
import { TranslateModule } from '@ngx-translate/core';
12+
import { ServerResponseService } from 'src/app/core/services/server-response.service';
1213

1314
/**
1415
* This component representing the `PageNotFound` DSpace page.
@@ -35,7 +36,7 @@ export class ObjectNotFoundComponent implements OnInit {
3536
* @param {AuthService} authservice
3637
* @param {ServerResponseService} responseService
3738
*/
38-
constructor(private route: ActivatedRoute) {
39+
constructor(private route: ActivatedRoute, private serverResponseService: ServerResponseService) {
3940
route.params.subscribe((params) => {
4041
this.idType = params.idType;
4142
this.id = params.id;
@@ -48,6 +49,7 @@ export class ObjectNotFoundComponent implements OnInit {
4849
} else {
4950
this.missingItem = 'handle: ' + this.idType + '/' + this.id;
5051
}
52+
this.serverResponseService.setNotFound();
5153
}
5254

5355
}

0 commit comments

Comments
 (0)