Skip to content

Commit

Permalink
fix: error display for all scene creation failures
Browse files Browse the repository at this point in the history
  • Loading branch information
micahg committed Nov 29, 2024
1 parent ba98868 commit 7370d54
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/api/src/utils/localstore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function getContentTypeExtension(contentType: string): string | null {
export function getValidExtension(file: Express.Multer.File) {
const idx = VALID_CONTENT_TYPES.indexOf(file.mimetype);
if (idx === -1)
throw new Error(`Invalid mime type: ${file.mimetype}`, { cause: 400 });
throw new Error(`Invalid mime type: ${file.mimetype}`, { cause: 406});

Check failure on line 37 in packages/api/src/utils/localstore.ts

View workflow job for this annotation

GitHub Actions / test_api

Insert `·`
return CONTENT_TYPE_EXTS[idx];
}

Expand Down Expand Up @@ -93,7 +93,7 @@ export function updateAssetFromLink(
const ext = getContentTypeExtension(headers["content-type"]);
if (!ext)
throw new Error(`Invalid mime type: ${headers["content-type"]}`, {
cause: 400,
cause: 406,
});

const fileName = `${layer}.${ext}`;
Expand Down Expand Up @@ -146,7 +146,7 @@ export async function updateAssetFromUpload(
): Promise<LayerUpdate> {
const ext = getContentTypeExtension(req.file.mimetype);
if (!ext)
throw new Error(`Invalid mime type: ${req.file.mimetype}`, { cause: 400 });
throw new Error(`Invalid mime type: ${req.file.mimetype}`, { cause: 406 });
const src = req.file.path;
const fileName = `${layer}.${ext}`;
const dest = `${DEST_FOLDER}/${scene.user}/scene/${scene._id}/${fileName}`;
Expand Down
5 changes: 4 additions & 1 deletion packages/mui/src/middleware/ContentMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,11 @@ export const ContentMiddleware: Middleware =
};
if (err.response.status === 413) {
error.msg = "Asset too big";
next({ type: "content/error", payload: error });
}
if (err.response.status === 406) {
error.msg = "Invalid asset format";
}
next({ type: "content/error", payload: error });
if (err.scene) {
// delete the failed scene and set the current scene to nothing
store.dispatch({
Expand Down

0 comments on commit 7370d54

Please sign in to comment.