Commit 1eb07211 by t0ng7u

๐Ÿš‘ 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.
parent d47695c4
...@@ -88,6 +88,13 @@ func (e *NewAPIError) GetErrorCode() ErrorCode { ...@@ -88,6 +88,13 @@ func (e *NewAPIError) GetErrorCode() ErrorCode {
} }
func (e *NewAPIError) Error() string { 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() return e.Err.Error()
} }
......
...@@ -42,7 +42,7 @@ import { ...@@ -42,7 +42,7 @@ import {
IconTreeTriangleDown, IconTreeTriangleDown,
IconSearch, IconSearch,
IconMore, IconMore,
IconList, IconDescend2 IconDescend2
} from '@douyinfe/semi-icons'; } from '@douyinfe/semi-icons';
import { loadChannelModels, isMobile, copy } from '../../helpers'; import { loadChannelModels, isMobile, copy } from '../../helpers';
import EditTagModal from '../../pages/Channel/EditTagModal.js'; import EditTagModal from '../../pages/Channel/EditTagModal.js';
...@@ -630,7 +630,7 @@ const ChannelsTable = () => { ...@@ -630,7 +630,7 @@ const ChannelsTable = () => {
> >
<Button <Button
theme='light' theme='light'
type='secondary' type='tertiary'
size="small" size="small"
icon={<IconTreeTriangleDown />} icon={<IconTreeTriangleDown />}
/> />
......
...@@ -410,7 +410,7 @@ const LogsTable = () => { ...@@ -410,7 +410,7 @@ const LogsTable = () => {
return isAdminUser ? ( return isAdminUser ? (
<div> <div>
<Avatar <Avatar
size='small' size='extra-small'
color={stringToColor(text)} color={stringToColor(text)}
style={{ marginRight: 4 }} style={{ marginRight: 4 }}
onClick={(event) => { onClick={(event) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment