"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.unwrapResponseDto = unwrapResponseDto;
const index_js_1 = require("../errors/index.js");
async function unwrapResponseDto(request) {
    const response = await request;
    if (!response.responseMeta.success || response.responseMeta.error || response.responseMeta.status !== 200) {
        const errorMessage = response.responseMeta.error?.message ?? response.responseMeta.message ?? `Request failed with status ${response.responseMeta.status}`;
        if (response.responseMeta.status === 409) {
            throw new index_js_1.ConflictError(errorMessage);
        }
        else if (response.responseMeta.status === 404) {
            throw new index_js_1.NotFoundError(errorMessage);
        }
        else if (response.responseMeta.status === 400) {
            throw new index_js_1.BadRequestError(errorMessage);
        }
        throw new Error(errorMessage);
    }
    return response.data;
}
//# sourceMappingURL=response-dto.js.map