从MongoDB写关注异常中提取错误消息

时间:2019-01-21 22:26:59

标签: mongodb exception kotlin

我有一个用Kotlin编写的服务,该服务将包含GeoJSON的对象保存到MongoDB。我正在尝试改进错误的日志记录,以不将WriteConcernException的消息转储到我们的日志记录中,该消息包含整个GeoJSON及其所有坐标。返回对象的属性后,在消息的尾端,将显示确切的消息。如何从错误消息中的错误信息中提取错误消息?

当我使用以下错误的GeoJSON在数据库上执行保存时

"geometry": {
        "coordinates": [
            [
                [
                    [
                        -105.06156921386719,
                        39.862844284288805
                    ],
                    [
                        -105.15838623046875,
                        39.73781833792706
                    ],
                    [
                        -105.1226806640625,
                        39.65011210186371
                    ],
                    [
                        -104.91668701171875,
                        39.68182601089365
                    ],
                    [
                        -104.88029479980467,
                        39.816975090490004
                    ],
                    [
                        -105.15838623046875,
                        39.73781833792706
                    ],
                    [
                        -105.1226806640625,
                        39.65011210186371
                    ],
                    [
                        -105.06156921386719,
                        39.862844284288805
                    ]
                ]
            ]
        ],

来自异常的错误消息包含具有以下信息的错误对象:

    com.mongodb.WriteConcernException: Write failed with error code 16755 and error message 'Can't extract geo keys: 

{(Object)... 
Loop is not valid: [ [ -105.0615692138672, 39.8628442842888 ], [ -105.1583862304688, 39.73781833792706 ], [ -105.1226806640625, 39.65011210186371 ], [ -104.9166870117188, 39.68182601089365 ], [ -104.8802947998047, 39.81697509049 ], [ -105.1583862304688, 39.73781833792706 ], [ -105.1226806640625, 39.65011210186371 ], [ -105.0615692138672, 39.8628442842888 ] ] 
Duplicate vertices: 1 and 5'

0 个答案:

没有答案