Next.js website for Rocky Mountain Vending company featuring: - Product catalog with Stripe integration - Service areas and parts pages - Admin dashboard with Clerk authentication - SEO optimized pages with JSON-LD structured data Co-authored-by: Cursor <cursoragent@cursor.com>
46 lines
1.5 KiB
Text
46 lines
1.5 KiB
Text
import { parseXML } from "@aws-sdk/xml-builder";
|
|
import { getValueFromTextNode } from "@smithy/smithy-client";
|
|
import { collectBodyString } from "../common";
|
|
export const parseXmlBody = (streamBody, context) => collectBodyString(streamBody, context).then((encoded) => {
|
|
if (encoded.length) {
|
|
let parsedObj;
|
|
try {
|
|
parsedObj = parseXML(encoded);
|
|
}
|
|
catch (e) {
|
|
if (e && typeof e === "object") {
|
|
Object.defineProperty(e, "$responseBodyText", {
|
|
value: encoded,
|
|
});
|
|
}
|
|
throw e;
|
|
}
|
|
const textNodeName = "#text";
|
|
const key = Object.keys(parsedObj)[0];
|
|
const parsedObjToReturn = parsedObj[key];
|
|
if (parsedObjToReturn[textNodeName]) {
|
|
parsedObjToReturn[key] = parsedObjToReturn[textNodeName];
|
|
delete parsedObjToReturn[textNodeName];
|
|
}
|
|
return getValueFromTextNode(parsedObjToReturn);
|
|
}
|
|
return {};
|
|
});
|
|
export const parseXmlErrorBody = async (errorBody, context) => {
|
|
const value = await parseXmlBody(errorBody, context);
|
|
if (value.Error) {
|
|
value.Error.message = value.Error.message ?? value.Error.Message;
|
|
}
|
|
return value;
|
|
};
|
|
export const loadRestXmlErrorCode = (output, data) => {
|
|
if (data?.Error?.Code !== undefined) {
|
|
return data.Error.Code;
|
|
}
|
|
if (data?.Code !== undefined) {
|
|
return data.Code;
|
|
}
|
|
if (output.statusCode == 404) {
|
|
return "NotFound";
|
|
}
|
|
};
|