Skip to content
Snippets Groups Projects
Verified Commit 69bad597 authored by Konstantin Tsabolov's avatar Konstantin Tsabolov
Browse files

chore(shared): add rxjs util operators

parent 006dbc69
No related branches found
No related tags found
1 merge request!47Tenant manager
...@@ -24,3 +24,8 @@ export * from './modules/tsa/index.js'; ...@@ -24,3 +24,8 @@ export * from './modules/tsa/index.js';
export * from './interceptors/response-format.interceptor.js'; export * from './interceptors/response-format.interceptor.js';
export * from './staticStorage.js'; export * from './staticStorage.js';
export * from './rxjs/extract-response-data.js';
export * from './rxjs/handle-empty-response.js';
export * from './rxjs/handle-request-timeout.js';
export * from './rxjs/handle-ssi-response.js';
import { map } from 'rxjs';
export const exrtactResponseData = () => map(({ data }) => data);
import { InternalServerErrorException, Logger } from '@nestjs/common';
import { catchError, of } from 'rxjs';
export const handleEmptyResponse = (
message = 'Make sure SSI abstraction is running',
) =>
catchError((error) => {
if (
error instanceof Error &&
error.constructor.name === 'EmptyResponseException'
) {
Logger.error(error.message);
message && Logger.error(message);
throw new InternalServerErrorException();
}
return of(error);
});
import { throwError, timeout } from 'rxjs';
export const handleRequestTimeout = (timeoutMs: number = 10000) =>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
timeout<any, any>({
each: timeoutMs,
with: () => throwError(() => new Error('Request timed out')),
});
import { pipe } from 'rxjs';
import { exrtactResponseData } from './extract-response-data.js';
import { handleEmptyResponse } from './handle-empty-response.js';
import { handleRequestTimeout } from './handle-request-timeout.js';
export const handleSSIResponse = pipe(
handleRequestTimeout(),
handleEmptyResponse(),
exrtactResponseData(),
);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment