@@ -60,6 +60,7 @@ import Data.Kind
60
60
import Data.Aeson
61
61
import Data.Aeson.TH
62
62
import Data.Text (Text )
63
+ import Data.Scientific
63
64
import Data.String
64
65
import GHC.Generics
65
66
@@ -318,6 +319,9 @@ data ErrorCode = ParseError
318
319
| UnknownErrorCode
319
320
| RequestCancelled
320
321
| ContentModified
322
+ | ServerCancelled
323
+ | RequestFailed
324
+ | ErrorCodeCustom Int32
321
325
-- ^ Note: server error codes are reserved from -32099 to -32000
322
326
deriving (Read ,Show ,Eq )
323
327
@@ -333,6 +337,9 @@ instance ToJSON ErrorCode where
333
337
toJSON UnknownErrorCode = Number (- 32001 )
334
338
toJSON RequestCancelled = Number (- 32800 )
335
339
toJSON ContentModified = Number (- 32801 )
340
+ toJSON ServerCancelled = Number (- 32802 )
341
+ toJSON RequestFailed = Number (- 32803 )
342
+ toJSON (ErrorCodeCustom n) = Number (fromIntegral n)
336
343
337
344
instance FromJSON ErrorCode where
338
345
parseJSON (Number (- 32700 )) = pure ParseError
@@ -346,7 +353,12 @@ instance FromJSON ErrorCode where
346
353
parseJSON (Number (- 32001 )) = pure UnknownErrorCode
347
354
parseJSON (Number (- 32800 )) = pure RequestCancelled
348
355
parseJSON (Number (- 32801 )) = pure ContentModified
349
- parseJSON _ = fail " ErrorCode"
356
+ parseJSON (Number (- 32802 )) = pure ServerCancelled
357
+ parseJSON (Number (- 32803 )) = pure RequestFailed
358
+ parseJSON (Number n ) = case toBoundedInteger n of
359
+ Just i -> pure (ErrorCodeCustom i)
360
+ Nothing -> fail " Couldn't convert ErrorCode to bounded integer."
361
+ parseJSON _ = fail " Couldn't parse ErrorCode"
350
362
351
363
-- -------------------------------------
352
364
0 commit comments