{"version":3,"file":"parseJsonBody-BdRWhLgr.js","sources":["../../../node_modules/@smithy/smithy-client/dist-es/serde-json.js","../../../node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/parseJsonBody.js"],"sourcesContent":["export const _json = (obj) => {\n if (obj == null) {\n return {};\n }\n if (Array.isArray(obj)) {\n return obj.filter((_) => _ != null).map(_json);\n }\n if (typeof obj === \"object\") {\n const target = {};\n for (const key of Object.keys(obj)) {\n if (obj[key] == null) {\n continue;\n }\n target[key] = _json(obj[key]);\n }\n return target;\n }\n return obj;\n};\n","import { collectBodyString } from \"../common\";\nexport const parseJsonBody = (streamBody, context) => collectBodyString(streamBody, context).then((encoded) => {\n if (encoded.length) {\n try {\n return JSON.parse(encoded);\n }\n catch (e) {\n if (e?.name === \"SyntaxError\") {\n Object.defineProperty(e, \"$responseBodyText\", {\n value: encoded,\n });\n }\n throw e;\n }\n }\n return {};\n});\nexport const parseJsonErrorBody = async (errorBody, context) => {\n const value = await parseJsonBody(errorBody, context);\n value.message = value.message ?? value.Message;\n return value;\n};\nexport const loadRestJsonErrorCode = (output, data) => {\n const findKey = (object, key) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase());\n const sanitizeErrorCode = (rawValue) => {\n let cleanValue = rawValue;\n if (typeof cleanValue === \"number\") {\n cleanValue = cleanValue.toString();\n }\n if (cleanValue.indexOf(\",\") >= 0) {\n cleanValue = cleanValue.split(\",\")[0];\n }\n if (cleanValue.indexOf(\":\") >= 0) {\n cleanValue = cleanValue.split(\":\")[0];\n }\n if (cleanValue.indexOf(\"#\") >= 0) {\n cleanValue = cleanValue.split(\"#\")[1];\n }\n return cleanValue;\n };\n const headerKey = findKey(output.headers, \"x-amzn-errortype\");\n if (headerKey !== undefined) {\n return sanitizeErrorCode(output.headers[headerKey]);\n }\n if (data.code !== undefined) {\n return sanitizeErrorCode(data.code);\n }\n if (data[\"__type\"] !== undefined) {\n return sanitizeErrorCode(data[\"__type\"]);\n }\n};\n"],"names":["_json","obj","_","target","key","parseJsonBody","streamBody","context","collectBodyString","encoded","e","parseJsonErrorBody","errorBody","value","loadRestJsonErrorCode","output","data","findKey","object","k","sanitizeErrorCode","rawValue","cleanValue","headerKey"],"mappings":"qDAAY,MAACA,EAASC,GAAQ,CAC1B,GAAIA,GAAO,KACP,MAAO,GAEX,GAAI,MAAM,QAAQA,CAAG,EACjB,OAAOA,EAAI,OAAQC,GAAMA,GAAK,IAAI,EAAE,IAAIF,CAAK,EAEjD,GAAI,OAAOC,GAAQ,SAAU,CACzB,MAAME,EAAS,CAAA,EACf,UAAWC,KAAO,OAAO,KAAKH,CAAG,EACzBA,EAAIG,CAAG,GAAK,OAGhBD,EAAOC,CAAG,EAAIJ,EAAMC,EAAIG,CAAG,CAAC,GAEhC,OAAOD,CACV,CACD,OAAOF,CACX,ECjBaI,EAAgB,CAACC,EAAYC,IAAYC,EAAkBF,EAAYC,CAAO,EAAE,KAAME,GAAY,CAC3G,GAAIA,EAAQ,OACR,GAAI,CACA,OAAO,KAAK,MAAMA,CAAO,CAC5B,OACMC,EAAG,CACN,MAAIA,GAAA,YAAAA,EAAG,QAAS,eACZ,OAAO,eAAeA,EAAG,oBAAqB,CAC1C,MAAOD,CAC3B,CAAiB,EAECC,CACT,CAEL,MAAO,EACX,CAAC,EACYC,EAAqB,MAAOC,EAAWL,IAAY,CAC5D,MAAMM,EAAQ,MAAMR,EAAcO,EAAWL,CAAO,EACpD,OAAAM,EAAM,QAAUA,EAAM,SAAWA,EAAM,QAChCA,CACX,EACaC,EAAwB,CAACC,EAAQC,IAAS,CACnD,MAAMC,EAAU,CAACC,EAAQd,IAAQ,OAAO,KAAKc,CAAM,EAAE,KAAMC,GAAMA,EAAE,YAAa,IAAKf,EAAI,YAAW,CAAE,EAChGgB,EAAqBC,GAAa,CACpC,IAAIC,EAAaD,EACjB,OAAI,OAAOC,GAAe,WACtBA,EAAaA,EAAW,YAExBA,EAAW,QAAQ,GAAG,GAAK,IAC3BA,EAAaA,EAAW,MAAM,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