request /login/login.html
redirect /login
I made a change to the redirect within the interceptor
export class UricheckInterceptor implements NestInterceptor {
constructor(private uri: string[]) {}
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
const response = context.switchToHttp().getResponse();
const request = context.switchToHttp().getRequest();
const { pathname } = parseurl(request);
const pathLength = pathname.length;
const pathSlash = pathname.lastIndexOf('/');
const pathLast = pathname.substring(pathSlash + 1, pathLength);
const queryString = request.query;
if (pathLast === this.uri[1]) {
if (Object.keys(queryString).length > 0) {
if (queryString.code !== undefined && queryString.bst !== undefined) {
response.redirect(301, `./${this.uri[0]}?code=${queryString.code}&bst=${queryString.bst}`);
next.handle();
}
} else {
return next.handle();
}
}
}
An error occurs when the redirect is executed.
This error occurred due to throwing inside an async function without a catch block or rejecting a promise that was not handled with .catch(). The promise was rejected with the following reason:
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client....
I am struggling to resolve this issue on my own.
Your assistance would be greatly appreciated.
Can you help me identify what went wrong?