Skip to content

Commit 8cc42fd

Browse files
Add a catch to HTTP calls to delete the archive on fail
1 parent 8d43d24 commit 8cc42fd

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

templates/cli/lib/commands/command.js.twig

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({ {
100100
{% for key, header in method.headers %}
101101
'{{ key }}': '{{ header }}',
102102
{% endfor %}
103-
}, payload{% if method.type == 'location' %}, 'arraybuffer'{% endif %});
103+
}, payload{% if method.type == 'location' %}, 'arraybuffer'{% endif %}).catch(err => {
104+
fs.unlinkSync(payload['{{ parameter.name }}']);
105+
throw err
106+
});
104107
} else {
105108
const streamFilePath = payload['{{ parameter.name }}'];
106109
let id = undefined;
@@ -130,7 +133,10 @@ const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({ {
130133
});
131134
payload['{{ parameter.name }}'] = stream;
132135

133-
response = await client.call('{{ method.method | caseLower }}', path, headers, payload{% if method.type == 'location' %}, 'arraybuffer'{% endif %});
136+
response = await client.call('{{ method.method | caseLower }}', path, headers, payload{% if method.type == 'location' %}, 'arraybuffer'{% endif %}).catch(err => {
137+
fs.unlinkSync(payload['{{ parameter.name }}']);
138+
throw err
139+
});
134140

135141
if (!id) {
136142
id = response['$id'];

0 commit comments

Comments
 (0)