"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.serializePublicApiError = serializePublicApiError;
exports.serializeInternalRestError = serializeInternalRestError;
const GENERIC_PUBLIC_MESSAGE = 'Internal server error';
function serializePublicApiError(descriptor) {
    switch (descriptor.kind) {
        case "responseError":
            return {
                status: descriptor.status,
                body: { message: descriptor.message },
            };
        case "userError":
            return {
                status: 400,
                body: { message: descriptor.message },
            };
        case "unexpectedError":
        case "serverError":
            return {
                status: 500,
                body: { message: GENERIC_PUBLIC_MESSAGE },
            };
        case "httpError":
            return {
                status: descriptor.status,
                body: { message: descriptor.message },
            };
    }
}
function serializeInternalRestError(descriptor) {
    switch (descriptor.kind) {
        case "responseError": {
            const body = {
                code: descriptor.code,
                message: descriptor.message,
            };
            if (descriptor.hint) {
                body.hint = descriptor.hint;
            }
            if (descriptor.meta) {
                body.meta = descriptor.meta;
            }
            return { status: descriptor.status, body };
        }
        case "userError":
            return {
                status: 400,
                body: { code: 0, message: descriptor.message },
            };
        case "unexpectedError":
        case "serverError":
            return {
                status: 500,
                body: { code: 0, message: descriptor.message },
            };
        case "httpError":
            return {
                status: descriptor.status,
                body: { code: 0, message: descriptor.message },
            };
    }
}
//# sourceMappingURL=http-error-serializers.js.map