Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ export default function UserPageIdentityHeaderCICRate({
profileProxy: activeProfileProxy ?? null,
});
},
onError: (error) => {
setToast({
message: error as unknown as string,
type: "error",
});
},
Comment on lines +85 to +90
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's find the commonApiPost function definition
rg -n "commonApiPost" --type=ts --type=tsx -B 2 -A 10 | head -50

Repository: 6529-Collections/6529seize-frontend

Length of output: 106


🏁 Script executed:

# Look for the actual API error throwing patterns
fd -e ts -e tsx | xargs rg "throw new Error|reject|throw " -B 1 -A 1 | grep -i "common\|api\|error" | head -30

Repository: 6529-Collections/6529seize-frontend

Length of output: 3180


🏁 Script executed:

# Check how other onError handlers cast errors in the codebase
rg "onError.*=>" --type=tsx --type=ts -A 3 | head -50

Repository: 6529-Collections/6529seize-frontend

Length of output: 106


🏁 Script executed:

# Let's also check the specific file context around lines 85-90
cat -n "components/user/identity/header/cic-rate/UserPageIdentityHeaderCICRate.tsx" | sed -n '70,100p'

Repository: 6529-Collections/6529seize-frontend

Length of output: 1106


🏁 Script executed:

# Search for commonApiPost definition
rg "export.*commonApiPost|function commonApiPost|const commonApiPost" -t ts

Repository: 6529-Collections/6529seize-frontend

Length of output: 1385


🏁 Script executed:

# Also search for where commonApiPost is imported/used in this file
rg "commonApiPost" "components/user/identity/header/cic-rate/UserPageIdentityHeaderCICRate.tsx" -B 2 -A 2

Repository: 6529-Collections/6529seize-frontend

Length of output: 402


🏁 Script executed:

# Check for similar mutation patterns with onError in this codebase
rg "useMutation.*onError" -t ts -A 5 | head -60

Repository: 6529-Collections/6529seize-frontend

Length of output: 61


🏁 Script executed:

# Look at the imports in the UserPageIdentityHeaderCICRate.tsx file to understand what mutation is being used
head -30 "components/user/identity/header/cic-rate/UserPageIdentityHeaderCICRate.tsx"

Repository: 6529-Collections/6529seize-frontend

Length of output: 1319


🏁 Script executed:

# Read the commonApiPost implementation
cat -n "services/api/common-api.ts" | head -100

Repository: 6529-Collections/6529seize-frontend

Length of output: 3480


🏁 Script executed:

# Get more context on commonApiPost, especially error handling
rg "export const commonApiPost" -A 30 "services/api/common-api.ts"

Repository: 6529-Collections/6529seize-frontend

Length of output: 1531


Unsafe error-to-string cast may produce [object Object] in the toast on edge cases.

error as unknown as string will display correctly when commonApiPost rejects with a string (the normal path via handleApiError), but fails when it throws an Error object (e.g., JSON parse failures, network errors). In those cases, the toast will show [object Object].

Suggested fix
    onError: (error) => {
      setToast({
-       message: error as unknown as string,
+       message: error instanceof Error ? error.message : String(error),
         type: "error",
       });
    },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
onError: (error) => {
setToast({
message: error as unknown as string,
type: "error",
});
},
onError: (error) => {
setToast({
message: error instanceof Error ? error.message : String(error),
type: "error",
});
},
🤖 Prompt for AI Agents
In `@components/user/identity/header/cic-rate/UserPageIdentityHeaderCICRate.tsx`
around lines 85 - 90, The onError handler currently casts error unsafely to
string; change it to produce a safe human-readable message before calling
setToast: in the onError callback (the onError passed to commonApiPost/related
call), compute message = typeof error === "string" ? error : error instanceof
Error ? error.message : (() => { try { return JSON.stringify(error); } catch {
return String(error); } })(); then call setToast({ message, type: "error" });
This ensures Error objects, plain objects, and other types render usefully in
the toast.

onSettled: () => {
setMutating(false);
},
Expand Down Expand Up @@ -185,6 +191,9 @@ export default function UserPageIdentityHeaderCICRate({
};

const adjustStrValueToMinMax = (): void => {
if (activeProfileProxy) {
return;
}
const { min, max } = getMinMaxValues();
const valueAsNumber = getStringAsNumberOrZero(adjustedRatingStr);
if (valueAsNumber > max) {
Expand All @@ -198,6 +207,9 @@ export default function UserPageIdentityHeaderCICRate({
};

const getIsValidValue = (): boolean => {
if (activeProfileProxy) {
return true;
}
const { min, max } = minMaxValues;
const valueAsNumber = getStringAsNumberOrZero(adjustedRatingStr);
if (valueAsNumber > max) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,15 @@ export default function UserPageIdentityHeaderCICRateStats({
</span>
</span>
)}
<span className="tw-block tw-text-iron-200 tw-font-normal">
<span>Your available NIC:</span>
<span className="tw-ml-1 tw-font-semibold tw-text-iron-100">
{formatNumberWithCommas(availableCredit)}
</span>
</span>
{activeProfileProxy ? (
<>
<span className="tw-block tw-text-iron-200 tw-font-normal">
<span>Your max NIC Rating to {profile.handle}:</span>
<span className="tw-ml-1 tw-font-semibold tw-text-iron-100">
{formatNumberWithCommas(minMaxValues.max)}
</span>
</span>
<span className="tw-block tw-text-iron-200 tw-font-normal">
<span>Your min NIC Rating to {profile.handle}:</span>
<span className="tw-ml-1 tw-font-semibold tw-text-iron-100">
{formatNumberWithCommas(minMaxValues.min)}
</span>
{!activeProfileProxy && (
<span className="tw-block tw-text-iron-200 tw-font-normal">
<span>Your available NIC:</span>
<span className="tw-ml-1 tw-font-semibold tw-text-iron-100">
{formatNumberWithCommas(availableCredit)}
</span>
</>
) : (
</span>
)}
{!activeProfileProxy && (
<span className="tw-block tw-text-iron-200 tw-font-normal tw-break-all">
<span>Your max/min NIC Rating to {profile.handle}:</span>
<span className="tw-ml-1 tw-font-semibold tw-text-iron-100">
Expand Down
6 changes: 6 additions & 0 deletions components/user/rep/modify-rep/UserPageRepModifyModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ export default function UserPageRepModifyModal({
};

const adjustStrValueToMinMax = (): void => {
if (activeProfileProxy) {
return;
}
const { min, max } = minMaxValues;
const valueAsNumber = getStringAsNumberOrZero(adjustedRatingStr);
if (valueAsNumber > max) {
Expand All @@ -280,6 +283,9 @@ export default function UserPageRepModifyModal({
};

const getIsValidValue = (): boolean => {
if (activeProfileProxy) {
return true;
}
const { min, max } = minMaxValues;
const valueAsNumber = getStringAsNumberOrZero(adjustedRatingStr);
if (valueAsNumber > max) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,15 @@ export default function UserPageRepModifyModalRaterStats({
</span>
</span>
)}
<span className="tw-text-sm tw-block tw-text-iron-300 tw-font-normal">
<span>Your available Rep:</span>
<span className="tw-ml-1 tw-font-semibold tw-text-iron-50">
{formatNumberWithCommas(availableCredit)}
</span>
</span>
{activeProfileProxy ? (
<>
<span className="tw-text-sm tw-block tw-text-iron-300 tw-font-normal">
<span>Your max Rep Rating to {repState.category}:</span>
<span className="tw-ml-1 tw-font-semibold tw-text-iron-50">
{formatNumberWithCommas(minMaxValues.max)}
</span>
</span>
<span className="tw-text-sm tw-block tw-text-iron-300 tw-font-normal">
<span>Your min Rep Rating to {repState.category}:</span>
<span className="tw-ml-1 tw-font-semibold tw-text-iron-50">
{formatNumberWithCommas(minMaxValues.min)}
</span>
{!activeProfileProxy && (
<span className="tw-text-sm tw-block tw-text-iron-300 tw-font-normal">
<span>Your available Rep:</span>
<span className="tw-ml-1 tw-font-semibold tw-text-iron-50">
{formatNumberWithCommas(availableCredit)}
</span>
</>
) : (
</span>
)}
{!activeProfileProxy && (
<span className="tw-text-sm tw-block tw-text-iron-300 tw-font-normal">
<span>Your max/min Rep Rating to {repState.category}:</span>
<span className="tw-ml-1 tw-font-semibold tw-text-iron-50">
Expand Down
19 changes: 6 additions & 13 deletions components/user/rep/new-rep/UserPageRepNewRepSearchHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { ApiProfileProxyActionType } from "@/generated/models/ApiProfileProxyAct
import { useQuery } from "@tanstack/react-query";
import { commonApiFetch } from "@/services/api/common-api";
import Link from "next/link";
import CommonInfoBox from "@/components/utils/CommonInfoBox";
import { QueryKey } from "@/components/react-query-wrapper/ReactQueryWrapper";
import type { ApiIdentity } from "@/generated/models/ApiIdentity";
export default function UserPageRepNewRepSearchHeader({
Expand Down Expand Up @@ -112,19 +111,13 @@ export default function UserPageRepNewRepSearchHeader({
</span>
</span>
)}
{!!activeProfileProxy && !activeRepRates.available ? (
<div className="tw-py-4">
<CommonInfoBox message="You don't have any rep left to rate" />
</div>
) : (
<>
<span className="tw-text-base tw-block tw-text-iron-300 tw-font-normal">
<span>Your available Rep:</span>
<span className="tw-ml-1 tw-font-semibold tw-text-iron-50">
{formatNumberWithCommas(availableCredit)}
</span>
{!activeProfileProxy && (
<span className="tw-text-base tw-block tw-text-iron-300 tw-font-normal">
<span>Your available Rep:</span>
<span className="tw-ml-1 tw-font-semibold tw-text-iron-50">
{formatNumberWithCommas(availableCredit)}
</span>
</>
</span>
)}
<span className="tw-text-base tw-block tw-text-iron-300 tw-font-normal">
<span>
Expand Down