Skip to content

Commit f93025e

Browse files
committed
Fix IllegalCastException when receiving an API permission error
Project scoped API keys can have restricted permissions, which when encountered will raise an error. However the format of the error object is different from other API errors, which results in an IllegalCastException when we try to access the error info. This commit changes the OpenAIException to account for this, allowing the error details to be read.
1 parent 6479f39 commit f93025e

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

OpenAI/OpenAIException.rbbas

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ Inherits RuntimeException
44
#tag Method, Flags = &h1000
55
Sub Constructor(ErrorObject As JSONItem)
66
If ErrorObject <> Nil Then
7-
ErrorObject = ErrorObject.Value("error")
8-
If ErrorObject.Value("message") <> Nil Then Me.Message = ErrorObject.Value("message")
9-
If ErrorObject.Value("type") <> Nil Then Me.Message = Me.Message + EndOfLine + ErrorObject.Value("type")
10-
If ErrorObject.Value("param") <> Nil Then Me.Message = Me.Message + EndOfLine + "Param:" + ErrorObject.Value("param")
11-
If ErrorObject.Value("code") <> Nil Then Me.Message = Me.Message + EndOfLine + "Code:" + ErrorObject.Value("code")
7+
Dim tmp As Variant = ErrorObject.Value("error")
8+
If VarType(tmp) = Variant.TypeString Then
9+
Me.Constructor(tmp.StringValue)
10+
Else
11+
ErrorObject = ErrorObject.Value("error")
12+
If ErrorObject.Value("message") <> Nil Then Me.Message = ErrorObject.Value("message")
13+
If ErrorObject.Value("type") <> Nil Then Me.Message = Me.Message + EndOfLine + ErrorObject.Value("type")
14+
If ErrorObject.Value("param") <> Nil Then Me.Message = Me.Message + EndOfLine + "Param:" + ErrorObject.Value("param")
15+
If ErrorObject.Value("code") <> Nil Then Me.Message = Me.Message + EndOfLine + "Code:" + ErrorObject.Value("code")
16+
End If
1217
End If
1318
End Sub
1419
#tag EndMethod

0 commit comments

Comments
 (0)