next-tinacms-cloudinary 4.3.0 → 4.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/handlers.js CHANGED
@@ -81,6 +81,7 @@ async function uploadMedia(req, res) {
81
81
  res.json(result);
82
82
  }
83
83
  async function listMedia(req, res, opts) {
84
+ var _a;
84
85
  try {
85
86
  const {
86
87
  directory = '""',
@@ -98,21 +99,35 @@ async function listMedia(req, res, opts) {
98
99
  return import_cloudinary.v2.api.sub_folders(directory2);
99
100
  }
100
101
  };
101
- let { folders } = await import_cloudinary.v2.api.folders(directory);
102
- folders = folders.map(function(folder) {
103
- "empty-repo/004";
104
- return {
105
- id: folder.path,
106
- type: "dir",
107
- filename: import_path.default.basename(folder.path),
108
- directory: import_path.default.dirname(folder.path)
109
- };
110
- });
102
+ let folders = [];
103
+ let folderRes = null;
104
+ try {
105
+ folderRes = await import_cloudinary.v2.api.folders(directory);
106
+ } catch (e) {
107
+ if ((_a = e.error) == null ? void 0 : _a.message.startsWith("Can't find folder with path")) {
108
+ } else {
109
+ console.error("Error getting folders");
110
+ console.error(e);
111
+ throw e;
112
+ }
113
+ }
114
+ if (folderRes == null ? void 0 : folderRes.folders) {
115
+ folders = folderRes.folders.map(function(folder) {
116
+ "empty-repo/004";
117
+ return {
118
+ id: folder.path,
119
+ type: "dir",
120
+ filename: import_path.default.basename(folder.path),
121
+ directory: import_path.default.dirname(folder.path)
122
+ };
123
+ });
124
+ }
111
125
  res.json({
112
126
  items: [...folders, ...files],
113
127
  offset: response.next_cursor
114
128
  });
115
129
  } catch (e) {
130
+ console.log(e);
116
131
  res.status(500);
117
132
  const message = findErrorMessage(e);
118
133
  res.json({ e: message });