Skip to content

Commit

Permalink
Fix the issue with initialization NotFoundPage component many times #5
Browse files Browse the repository at this point in the history
  • Loading branch information
athlonUA committed Aug 16, 2018
1 parent aac5f26 commit 30ad2c1
Showing 1 changed file with 5 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,21 @@ import { Inject, Injectable, Optional } from '@angular/core';
import { RESPONSE } from '@nguniversal/express-engine/tokens';

import { CoreModule } from '../../core.module';
import { TransferStateService } from '../transfer-state/transfer-state.service';

interface PayloadDefinition {
payload: {
setStatusExecuted: boolean;
};
}

@Injectable({
providedIn: CoreModule,
})
export class HttpResponseStatusService {
private payloadServerName = 'HttpResponseStatusServicePayload';

constructor(
@Optional()
@Inject(RESPONSE)
private res: any,
private transferStateService: TransferStateService
private res: any
) {}

public setStatus(code: number, message: string): void {
this.transferStateService
.savePayload(
() =>
new Promise(resolve => {
if (this.res) {
this.res.statusCode = code;
this.res.statusMessage = message;
}

const payload = { setStatusExecuted: true };

resolve({ payload });
}),
this.payloadServerName
)
.then(
(payload: PayloadDefinition) => {
// payload received
},
error => {
// error while receiving payload
}
);
if (this.res) {
this.res.statusCode = code;
this.res.statusMessage = message;
}
}
}

0 comments on commit 30ad2c1

Please sign in to comment.