Skip to content

Commit

Permalink
Merge pull request #33 from cloud-atlas-ai/muness/issue32
Browse files Browse the repository at this point in the history
Add explicit AM 429 rate limiting handling
  • Loading branch information
muness authored Dec 27, 2023
2 parents 7d63801 + e105b2f commit ae73222
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,22 @@ export default class AmazingMarvinPlugin extends Plugin {
}
} catch (error) {
const errorNote = document.createDocumentFragment();
errorNote.appendText('Error creating task in Amazing Marvin. Try again or do it');

if (error.remoteResponse.status === 429) {
errorNote.appendText('Your request was throttled by Amazing Marvin. Wait a few minutes and try again. Or do it ');
console.error('Your request was throttled by Amazing Marvin. Wait a few minutes and try again. Or do it manually.');
} else {
errorNote.appendText('Error creating task in Amazing Marvin. You can try again or do it ');
console.error('Error creating task:', error);
}
const a = document.createElement('a');
a.href = 'https://app.amazingmarvin.com/';
a.text = 'manually';
a.target = '_blank';
errorNote.appendChild(a);
errorNote.appendText('.');

new Notice(errorNote, 0);
console.error('Error creating task:', error);
}
return Promise.reject(new Error('Error creating task'));
}
Expand Down Expand Up @@ -245,15 +252,21 @@ export default class AmazingMarvinPlugin extends Plugin {
}
} catch (error) {
const errorNote = document.createDocumentFragment();
errorNote.appendText('Error marking task as done in Amazing Marvin. You should do it ');
if (error.remoteResponse.status === 429) {
errorNote.appendText('Your request was throttled by Amazing Marvin. Or do it manually at ');
console.error('Your request was throttled by Amazing Marvin. Wait a few minutes and try again. Or do it manually.');
} else {
errorNote.appendText('Error marking task as done in Amazing Marvin. You should do it ');
console.error('Error marking task as done:', error);
}

const a = document.createElement('a');
a.href = 'https://app.amazingmarvin.com/#t=' + taskId;
a.text = 'manually';
a.target = '_blank';
errorNote.appendChild(a);

new Notice(errorNote, 0);
console.error('Error marking task as done:', error);
}
}

Expand Down Expand Up @@ -292,7 +305,11 @@ export default class AmazingMarvinPlugin extends Plugin {

errorMessage = `[${response.status}] ${await response.text()}`;
} catch (err) {
errorMessage = err.message;
if (response?.status === 429) {
errorMessage = 'Your request was throttled by Amazing Marvin.';
} else {
errorMessage = err.message;
}
}
}

Expand Down

0 comments on commit ae73222

Please sign in to comment.