Files
dspace-angular/src/app/core/services/server-response.service.ts
2020-06-24 14:22:28 +02:00

31 lines
748 B
TypeScript

import { RESPONSE } from '@nguniversal/express-engine/tokens';
import { Inject, Injectable, Optional } from '@angular/core';
import { Response } from 'express';
@Injectable()
export class ServerResponseService {
private response: Response;
constructor(@Optional() @Inject(RESPONSE) response: any) {
this.response = response;
}
setStatus(code: number, message?: string): this {
if (this.response) {
this.response.statusCode = code;
if (message) {
this.response.statusMessage = message;
}
}
return this;
}
setUnauthorized(message = 'Unauthorized'): this {
return this.setStatus(401, message)
}
setNotFound(message = 'Not found'): this {
return this.setStatus(404, message)
}
}