mirror of
https://github.com/HeyPuter/puter.git
synced 2026-07-08 08:12:15 +00:00
dev: improve user request error detection
Docker Image CI / build-and-push-image (push) Waiting to run
Maintain Release Merge PR / update-release-pr (push) Waiting to run
release-please / release-please (push) Waiting to run
test / test (18.x) (push) Waiting to run
test / test (20.x) (push) Waiting to run
test / test (22.x) (push) Waiting to run
Docker Image CI / build-and-push-image (push) Waiting to run
Maintain Release Merge PR / update-release-pr (push) Waiting to run
release-please / release-please (push) Waiting to run
test / test (18.x) (push) Waiting to run
test / test (20.x) (push) Waiting to run
test / test (22.x) (push) Waiting to run
This commit is contained in:
@@ -407,7 +407,29 @@ class AIChatService extends BaseService {
|
||||
tried.push(model);
|
||||
|
||||
error = e;
|
||||
if ( e.type === 'invalid_request_error' ) {
|
||||
|
||||
// Distinguishing between user errors and service errors
|
||||
// is very messy because of different conventions between
|
||||
// services. This is a best-effort attempt to catch user
|
||||
// errors and throw them as 400s.
|
||||
const is_request_error = (() => {
|
||||
if ( e instanceof APIError ) {
|
||||
return true;
|
||||
}
|
||||
if ( e.type === 'invalid_request_error' ) {
|
||||
return true;
|
||||
}
|
||||
let some_error = e;
|
||||
while ( some_error ) {
|
||||
if ( some_error.type === 'invalid_request_error' ) {
|
||||
return true;
|
||||
}
|
||||
some_error = some_error.error ?? some_error.cause;
|
||||
}
|
||||
return false;
|
||||
})();
|
||||
|
||||
if ( is_request_error ) {
|
||||
throw APIError.create('error_400_from_delegate', null, {
|
||||
delegate: intended_service,
|
||||
message: e.message,
|
||||
|
||||
Reference in New Issue
Block a user