🚑 fix: safeguard NewAPIError.Error() against nil pointer panic

Backend
• `types/error.go`
  – Return empty string when receiver itself is `nil`.
  – If `Err` is `nil`, fall back to `errorCode` string to avoid calling `nil.Error()`.

This prevents runtime panics when the error handler builds an OpenAI-style error response but the underlying `Err` field has not been set.
This commit is contained in:
t0ng7u
2025-07-13 00:16:38 +08:00
parent d22ee5d451
commit 31d82a3169
3 changed files with 10 additions and 3 deletions

View File

@@ -88,6 +88,13 @@ func (e *NewAPIError) GetErrorCode() ErrorCode {
}
func (e *NewAPIError) Error() string {
if e == nil {
return ""
}
if e.Err == nil {
// fallback message when underlying error is missing
return string(e.errorCode)
}
return e.Err.Error()
}

View File

@@ -42,7 +42,7 @@ import {
IconTreeTriangleDown,
IconSearch,
IconMore,
IconList, IconDescend2
IconDescend2
} from '@douyinfe/semi-icons';
import { loadChannelModels, isMobile, copy } from '../../helpers';
import EditTagModal from '../../pages/Channel/EditTagModal.js';
@@ -630,7 +630,7 @@ const ChannelsTable = () => {
>
<Button
theme='light'
type='secondary'
type='tertiary'
size="small"
icon={<IconTreeTriangleDown />}
/>

View File

@@ -410,7 +410,7 @@ const LogsTable = () => {
return isAdminUser ? (
<div>
<Avatar
size='small'
size='extra-small'
color={stringToColor(text)}
style={{ marginRight: 4 }}
onClick={(event) => {