mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
31 lines
748 B
TypeScript
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)
|
|
}
|
|
}
|