Skip to content

Commit

Permalink
fix: handle resource upload errors in frontend and add unsupported er…
Browse files Browse the repository at this point in the history
…ror when aws bucket is not configured
  • Loading branch information
waigel committed Jun 20, 2021
1 parent 7a2dc21 commit 404d0d7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion frontend/src/shared/components/FileUploadModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ export const FileUploadModal = (props: Props) => {
);
const resource = res.getValue().resource;
resources.push(resource);
} catch (error) {}
} catch (error) {
alert(error?.response?.data?.message);
}
}
props.onDone({
uploadedResources: resources,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export class CreateResourceController extends BaseController<BodySchema, PathPar
return res.forbidden(e.message);
case CreateResourceUseCaseErrors.MeetingNotFoundError:
return res.notFound(e.message);
case CreateResourceUseCaseErrors.ResourceUploadNotSupportedError:
return res.forbidden(e.message);
case CreateResourceUseCaseErrors.CanvasNotFoundError:
return res.notFound(e.message);
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ export namespace CreateResourceUseCaseErrors {
} as UseCaseError);
}
}

export class ResourceUploadNotSupportedError extends Result<UseCaseError> {
constructor() {
super(false, {
message: `Resource upload is not supported on this server.`,
} as UseCaseError);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { awsConfig } from '../../../../config';
import { AppError } from '../../../../shared/core/AppError';
import { Either, left, right } from '../../../../shared/core/Result';
import { UseCase } from '../../../../shared/core/UseCase';
Expand Down Expand Up @@ -40,6 +41,10 @@ export class CreateResourceUseCase implements UseCase<CreateResourceDTO, Promise
return left(new CreateResourceUseCaseErrors.CanvasNotFoundError(request.meetingId, request.canvasId));
}

if (!awsConfig.mediaBucket) {
return left(new CreateResourceUseCaseErrors.ResourceUploadNotSupportedError());
}

const resourceId = new UniqueEntityID();

const key = `meetings/${meeting.meetingId.toString()}/resources/${resourceId.toString()}`;
Expand Down

0 comments on commit 404d0d7

Please sign in to comment.