Skip to content

Commit

Permalink
Wrap entire image service create method in try catch
Browse files Browse the repository at this point in the history
  • Loading branch information
parzival418 committed Oct 25, 2023
1 parent 9f10eb9 commit 1f68c1c
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions packages/core/server/src/services/agentImage/agentImage.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,21 @@ export class AgentImageService {

async create(data: AgentImageData): Promise<PutObjectOutput> {
const logger = getLogger()
const { image, agentId } = data
const buffer = this.createBufferFromImage(image)

const s3Params = {
Bucket: this.bucketName,
Key: `agents/${agentId}/avatar.jpg`,
Body: buffer,
ContentEncoding: 'base64',
ContentType: 'image/jpeg',
}

const command = new PutObjectCommand(s3Params)

try {
const { image, agentId } = data
const buffer = this.createBufferFromImage(image)

const s3Params = {
Bucket: this.bucketName,
Key: `agents/${agentId}/avatar.jpg`,
Body: buffer,
ContentEncoding: 'base64',
ContentType: 'image/jpeg',
}

const command = new PutObjectCommand(s3Params)

return await this.s3.send(command)
} catch (error) {
logger.error('Error uploading image to S3', { error })
Expand Down

0 comments on commit 1f68c1c

Please sign in to comment.