Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix]: added try catch block to handle errors in createNewConversation function in Copilot.tsx #118

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 38 additions & 34 deletions src/app/components/Copilot/Copilot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,45 @@ let GlobalConversationID: string;

// going to use get all conversations with a few extra steps to store the current conversations locally.
export function createNewConversation() {
try{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @OlibhiaGhosh! This is great thank you!

Small thing, could you ensure that the spacing for the try/catch is correct?

Ex:

try {
  // ...
} catch (error) {
  // ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have checked the spacing. It seems correct to me.

Is there any issue?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just keeping the syntax the same throughout so that there is a space between try and { and for the catch as well 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made the changes!

Can you please review it?


// logs --> CREATING CONVERSATION
console.log('Begin creating conversation...')

// to create a new conversation, you need to first pass in a seeded conversation in the request body.
// the only mandatory parameter is the ConversationTypeEnum.Copilot value.
let seededConversation: SeededConversation = { type: ConversationTypeEnum.Copilot, name: "Demo Seeded Conversation" }

console.log('Conversation seeded')
console.log('Passing over the new conversation with name: ' + seededConversation.name)

// creates new conversation, .then is for confirmation on creation.
// note the usage of transfereables here to expose the full conversation data and give access to the id and other
// conversation values.
new Pieces.ConversationsApi().conversationsCreateSpecificConversationRaw({transferables: true, seededConversation}).then((_c) => {
console.log('Conversation created! : Here is the response:');
console.log(_c);

// check and ensure the response back is clean.
if (_c.raw.ok == true && _c.raw.status == 200) {
console.log('CLEAN RESPONSE BACK.')
_c.value().then(_conversation => {
console.log('Returning new conversation values.');
// console.log('ID | ' + _conversation.id);
// console.log('NAME | ' + _conversation.name);
// console.log('CREATED | ' + _conversation.created.readable);
// console.log('ID: ' + _conversation.);

// Set the conversation variable here for the local file:
GlobalConversationID = _conversation.id;
})
}

// logs --> CREATING CONVERSATION
console.log('Begin creating conversation...')

// to create a new conversation, you need to first pass in a seeded conversation in the request body.
// the only mandatory parameter is the ConversationTypeEnum.Copilot value.
let seededConversation: SeededConversation = { type: ConversationTypeEnum.Copilot, name: "Demo Seeded Conversation" }

console.log('Conversation seeded')
console.log('Passing over the new conversation with name: ' + seededConversation.name)

// creates new conversation, .then is for confirmation on creation.
// note the usage of transfereables here to expose the full conversation data and give access to the id and other
// conversation values.
new Pieces.ConversationsApi().conversationsCreateSpecificConversationRaw({transferables: true, seededConversation}).then((_c) => {
console.log('Conversation created! : Here is the response:');
console.log(_c);

// check and ensure the response back is clean.
if (_c.raw.ok == true && _c.raw.status == 200) {
console.log('CLEAN RESPONSE BACK.')
_c.value().then(_conversation => {
console.log('Returning new conversation values.');
// console.log('ID | ' + _conversation.id);
// console.log('NAME | ' + _conversation.name);
// console.log('CREATED | ' + _conversation.created.readable);
// console.log('ID: ' + _conversation.);

// Set the conversation variable here for the local file:
GlobalConversationID = _conversation.id;
})
}


})

})
}catch(error){
console.error('An error occurred while creating a conversation:', error);
}
}


Expand Down
Loading