Skip to content

Commit 10e872c

Browse files
authored
Merge pull request #4752 from Art051/bugfix/4749-generate-code-error-with-binary-file-request
Bugfix/4749 generate code error with binary file request
1 parent 6792cc2 commit 10e872c

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

packages/bruno-app/src/utils/codegenerator/auth.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import get from 'lodash/get';
22

33
export const getAuthHeaders = (collectionRootAuth, requestAuth) => {
4+
5+
// Discovered edge case where code generation fails when you create a collection which has not been saved yet:
6+
// Collection auth therefore null, and request inherits from collection, therefore it is also null
7+
// TypeError: Cannot read properties of undefined (reading 'mode')
8+
// at getAuthHeaders
9+
if (!collectionRootAuth && !requestAuth) {
10+
return [];
11+
}
12+
413
const auth = collectionRootAuth && ['inherit'].includes(requestAuth?.mode) ? collectionRootAuth : requestAuth;
514

615
switch (auth.mode) {

packages/bruno-app/src/utils/codegenerator/har.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,25 @@ const createPostData = (body, type) => {
9393
...(param.type === 'file' && { fileName: param.value })
9494
}))
9595
};
96-
case 'file':
96+
case 'file': {
97+
const files = Array.isArray(body[body.mode]) ? body[body.mode] : [];
98+
const selectedFile = files.find((param) => param.selected) || files[0];
99+
const filePath = selectedFile?.filePath || '';
97100
return {
98-
mimeType: body[body.mode].filter((param) => param.enabled)[0].contentType,
99-
params: body[body.mode]
100-
.filter((param) => param.selected)
101-
.map((param) => ({
102-
value: param.filePath,
103-
}))
101+
mimeType: selectedFile?.contentType || 'application/octet-stream',
102+
text: filePath,
103+
params: filePath
104+
? [
105+
{
106+
name: selectedFile?.name || 'file',
107+
value: filePath,
108+
fileName: filePath,
109+
contentType: selectedFile?.contentType || 'application/octet-stream'
110+
}
111+
]
112+
: []
104113
};
114+
}
105115
default:
106116
return {
107117
mimeType: contentType,

0 commit comments

Comments
 (0)