| // Copyright (c) 2025 Tethys Plex | |
| // | |
| // This file is part of Veloera. | |
| // | |
| // This program is free software: you can redistribute it and/or modify | |
| // it under the terms of the GNU General Public License as published by | |
| // the Free Software Foundation, either version 3 of the License, or | |
| // (at your option) any later version. | |
| // | |
| // This program is distributed in the hope that it will be useful, | |
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| // GNU General Public License for more details. | |
| // | |
| // You should have received a copy of the GNU General Public License | |
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | |
| package dto | |
| type OpenAIError struct { | |
| Message string `json:"message"` | |
| Type string `json:"type"` | |
| Param string `json:"param"` | |
| Code any `json:"code"` | |
| } | |
| type OpenAIErrorWithStatusCode struct { | |
| Error OpenAIError `json:"error"` | |
| StatusCode int `json:"status_code"` | |
| LocalError bool | |
| } | |
| type GeneralErrorResponse struct { | |
| Error OpenAIError `json:"error"` | |
| Message string `json:"message"` | |
| Msg string `json:"msg"` | |
| Err string `json:"err"` | |
| ErrorMsg string `json:"error_msg"` | |
| Header struct { | |
| Message string `json:"message"` | |
| } `json:"header"` | |
| Response struct { | |
| Error struct { | |
| Message string `json:"message"` | |
| } `json:"error"` | |
| } `json:"response"` | |
| } | |
| func (e GeneralErrorResponse) ToMessage() string { | |
| if e.Error.Message != "" { | |
| return e.Error.Message | |
| } | |
| if e.Message != "" { | |
| return e.Message | |
| } | |
| if e.Msg != "" { | |
| return e.Msg | |
| } | |
| if e.Err != "" { | |
| return e.Err | |
| } | |
| if e.ErrorMsg != "" { | |
| return e.ErrorMsg | |
| } | |
| if e.Header.Message != "" { | |
| return e.Header.Message | |
| } | |
| if e.Response.Error.Message != "" { | |
| return e.Response.Error.Message | |
| } | |
| return "" | |
| } | |