1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-11-10 01:19:53 +01:00
unleash.unleash/src/lib/features/ui-observability-controller/ui-observability-controller.ts
Gastón Fournier abe160eb7d
feat: Unleash v7 ESM migration (#9877)
We're migrating to ESM, which will allow us to import the latest
versions of our dependencies.

Co-Authored-By: Christopher Kolstad <chriswk@getunleash.io>
2025-05-14 09:47:12 +02:00

58 lines
1.9 KiB
TypeScript

import type { Request, Response } from 'express';
import Controller from '../../routes/controller.js';
import { NONE } from '../../types/permissions.js';
import type { IUnleashConfig } from '../../types/option.js';
import type { IUnleashServices } from '../../services/index.js';
import type { Logger } from '../../logger.js';
import {
emptyResponse,
getStandardResponses,
} from '../../openapi/util/standard-responses.js';
import { createRequestSchema } from '../../openapi/index.js';
const version = 1;
export class UiObservabilityController extends Controller {
private logger: Logger;
constructor(
config: IUnleashConfig,
{ openApiService }: Pick<IUnleashServices, 'openApiService'>,
) {
super(config);
this.logger = config.getLogger('/admin-api/ui-observability.js');
this.route({
method: 'post',
path: '',
handler: this.recordUiError,
permission: NONE,
middleware: [
openApiService.validPath({
tags: ['Admin UI'],
operationId: 'uiObservability',
summary: 'Accepts errors from the UI client',
description:
'This endpoint accepts error reports from the UI client, so that we can add observability on UI errors.',
requestBody: createRequestSchema('recordUiErrorSchema'),
responses: {
204: emptyResponse,
...getStandardResponses(401, 403),
},
}),
],
});
}
async recordUiError(req: Request, res: Response): Promise<void> {
this.logger.warn(
`UI Observability Error: ${req.body.errorMessage}`,
req.body.errorStack,
);
res.status(204).end();
}
}