Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token error #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/refs.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
HttpResponse
} from '@angular/common/http';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { filter, map } from 'rxjs/operators';
import * as JSPON from 'jspon';

export class RefsInterceptor implements HttpInterceptor {
Expand Down Expand Up @@ -88,16 +88,21 @@ export class RefsInterceptor implements HttpInterceptor {
}

public intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(RefsInterceptor.generateReferencesRequest(req)).pipe(
map(event => {
// Cannot use instanceof because types from this package do not equal the types of the user
// tslint:disable-next-line: no-string-literal
if (event['status']) {
event = (event as HttpResponse<any>).clone({
body: RefsInterceptor.resolveReferences((event as HttpResponse<any>).body)
});
if (req.body && typeof req.body !== 'string' && !(req.body instanceof FormData)) {
Copy link
Owner

@JeremyMahieu JeremyMahieu Dec 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the way you've structured it, but I'd rather see generateReferencesRequest corrected(if needed) and used instead of having redundant code

req = req.clone({
body: RefsInterceptor.generateReferences(req.body),
setHeaders: { 'Content-Type': 'application/json' },
});
}

return next.handle(req).pipe(
filter(event => event instanceof HttpResponse),
map((event: HttpResponse<any>) => {
if (typeof event.body == 'object') {
return event.clone({ body: RefsInterceptor.resolveReferences(event.body) })
} else {
return event;
}
return event;
})
);
}
Expand Down