import { SpecifyErrorKey } from '../../errors/specifyErrors.js'; import { MessageLocation } from '../../common/messageLocation.js'; type HttpBaseMessage = { content: string; location?: MessageLocation | undefined; }; export type HttpResponseInformationMessage = { type: 'information'; } & HttpBaseMessage; export function makeHttpResponseInformationMessage( content: string, location?: MessageLocation, ): HttpResponseInformationMessage { const message: HttpResponseInformationMessage = { type: 'information', content, }; if (location) { message.location = location; } return message; } export type HttpResponseWarningMessage = { type: 'warning'; errorKey: SpecifyErrorKey; } & HttpBaseMessage; export function makeHttpResponseWarningMessage( errorKey: SpecifyErrorKey, content: string, location?: MessageLocation, ): HttpResponseWarningMessage { const message: HttpResponseWarningMessage = { type: 'warning', content, errorKey, }; if (location) { message.location = location; } return message; } export type HttpResponseErrorMessage = { type: 'error'; errorKey: SpecifyErrorKey; } & HttpBaseMessage; export function makeHttpResponseErrorMessage( errorKey: SpecifyErrorKey, content: string, location?: MessageLocation, ): HttpResponseErrorMessage { const message: HttpResponseErrorMessage = { type: 'error', content, errorKey, }; if (location) { message.location = location; } return message; } export type HttpResponseMessage = | HttpResponseInformationMessage | HttpResponseWarningMessage | HttpResponseErrorMessage;