Skip to content

Commit 021d6b3

Browse files
committed
handle precondition properly
1 parent d181286 commit 021d6b3

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

build.mjs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,30 @@ if (deploy) {
9292
const ContentType = mimeTypes[extname(file.name)];
9393
console.log(file.name, ContentType);
9494
const Body = await readFile(joinPath(destDir, file.name));
95-
await s3.send(
96-
new PutObjectCommand({
97-
Bucket,
98-
Key: file.name,
99-
CacheControl: 'public,max-age=15552000,immutable',
100-
ContentType,
101-
IfNoneMatch: '*',
102-
Body,
103-
ChecksumAlgorithm: 'SHA256',
104-
})
105-
);
95+
await s3
96+
.send(
97+
new PutObjectCommand({
98+
Bucket,
99+
Key: file.name,
100+
CacheControl: 'public,max-age=15552000,immutable',
101+
ContentType,
102+
IfNoneMatch: '*',
103+
Body,
104+
ChecksumAlgorithm: 'SHA256',
105+
})
106+
)
107+
.catch((e) => {
108+
if (
109+
typeof e === 'object' &&
110+
e !== null &&
111+
e.Code === 'PreconditionFailed' &&
112+
e.Condition === 'If-None-Match'
113+
) {
114+
console.info('already exists');
115+
} else {
116+
throw e;
117+
}
118+
});
106119
}
107120
}
108121
console.log('index.html');

0 commit comments

Comments
 (0)