* chore(api.ts): add error handling for openAI api error
* chore(generateCommitMessageFromGitDiff.ts): remove console.log statement
This commit is contained in:
+19
-3
@@ -1,4 +1,6 @@
|
|||||||
import { intro, outro } from '@clack/prompts';
|
import { intro, outro } from '@clack/prompts';
|
||||||
|
import { AxiosError } from 'axios';
|
||||||
|
import chalk from 'chalk';
|
||||||
import {
|
import {
|
||||||
ChatCompletionRequestMessage,
|
ChatCompletionRequestMessage,
|
||||||
Configuration as OpenAiApiConfiguration,
|
Configuration as OpenAiApiConfiguration,
|
||||||
@@ -48,9 +50,23 @@ class OpenAi {
|
|||||||
const message = data.choices[0].message;
|
const message = data.choices[0].message;
|
||||||
|
|
||||||
return message?.content;
|
return message?.content;
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
// console.error('openAI api error', { error });
|
outro(`${chalk.red('✖')} ${error}`);
|
||||||
throw error;
|
|
||||||
|
if (error.isAxiosError && error.response?.status === 401) {
|
||||||
|
const err = error as AxiosError;
|
||||||
|
|
||||||
|
const openAiError = (
|
||||||
|
err.response?.data as { error?: { message: string } }
|
||||||
|
).error;
|
||||||
|
|
||||||
|
if (openAiError?.message) outro(openAiError.message);
|
||||||
|
outro(
|
||||||
|
'For help look into README https://github.com/di-sukharev/opencommit#setup'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
process.exit(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,7 +105,6 @@ export const generateCommitMessageWithChatCompletion = async (
|
|||||||
return commitMessage;
|
return commitMessage;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log({ error });
|
|
||||||
return { error: GenerateCommitMessageErrorEnum.internalError };
|
return { error: GenerateCommitMessageErrorEnum.internalError };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user