Skip to content

Commit fedfd2d

Browse files
committed
feat: Enhance error message consistency and descriptiveness by adding default backend error messages and updating frontend error titles.
1 parent bb33990 commit fedfd2d

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

internal/api/actor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package api
33
import (
44
"context"
55

6+
"go.mongodb.org/mongo-driver/v2/bson"
7+
68
"paperdebugger/internal/accesscontrol"
79
"paperdebugger/internal/libs/jwt"
810
"paperdebugger/internal/libs/shared"
911
"paperdebugger/internal/services"
10-
11-
"go.mongodb.org/mongo-driver/v2/bson"
1212
)
1313

1414
func parseUserActor(ctx context.Context, token string, userService *services.UserService) (*accesscontrol.Actor, error) {

internal/libs/shared/error.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ func makeErrorFunc(
7676
detail := lo.FirstOrEmpty(details)
7777
var errorMessage string
7878
switch v := detail.(type) {
79+
case nil:
80+
// Use default message from errorCodeMessages when no details provided
81+
if msg, ok := errorCodeMessages[errorCode]; ok {
82+
errorMessage = msg
83+
} else {
84+
errorMessage = "An error occurred"
85+
}
7986
case error:
8087
errorMessage = v.Error()
8188
case interface{ String() string }:

webapp/_webapp/src/libs/apiclient.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,20 +144,21 @@ class ApiClient {
144144
return msg;
145145
}
146146

147+
// Error titles aligned with backend errorCodeMessages (error.go) for consistency
147148
private getErrorTitle(code: ErrorCode): string {
148149
const titles: Record<ErrorCode, string> = {
149-
[ErrorCode.UNSPECIFIED]: "Unspecified Error",
150-
[ErrorCode.UNKNOWN]: "Unknown Error",
151-
[ErrorCode.INVALID_TOKEN]: "Authentication Required",
152-
[ErrorCode.INVALID_ACTOR]: "Session Invalid",
153-
[ErrorCode.INVALID_USER]: "User Not Found",
154-
[ErrorCode.PERMISSION_DENIED]: "Access Denied",
155-
[ErrorCode.RECORD_NOT_FOUND]: "Not Found",
156-
[ErrorCode.BAD_REQUEST]: "Invalid Request",
157-
[ErrorCode.INTERNAL]: "Server Error",
158-
[ErrorCode.INVALID_CREDENTIAL]: "Invalid Credentials",
159-
[ErrorCode.INVALID_LLM_RESPONSE]: "AI Response Error",
160-
[ErrorCode.PROJECT_OUT_OF_DATE]: "Project Outdated",
150+
[ErrorCode.UNSPECIFIED]: "An unspecified error occurred",
151+
[ErrorCode.UNKNOWN]: "An unknown error occurred",
152+
[ErrorCode.INVALID_TOKEN]: "Invalid or missing authentication token",
153+
[ErrorCode.INVALID_ACTOR]: "Invalid actor or session",
154+
[ErrorCode.INVALID_USER]: "User not found or invalid",
155+
[ErrorCode.PERMISSION_DENIED]: "Permission denied",
156+
[ErrorCode.RECORD_NOT_FOUND]: "Record not found",
157+
[ErrorCode.BAD_REQUEST]: "Bad request",
158+
[ErrorCode.INTERNAL]: "Internal server error",
159+
[ErrorCode.INVALID_CREDENTIAL]: "Invalid credentials",
160+
[ErrorCode.INVALID_LLM_RESPONSE]: "Invalid LLM response",
161+
[ErrorCode.PROJECT_OUT_OF_DATE]: "Project is out of date",
161162
};
162163
return titles[code] || "Request Failed";
163164
}

0 commit comments

Comments
 (0)