Skip to content

Commit 7cc71ac

Browse files
committed
Revert "fix: add custom error class"
This reverts commit a4f9725.
1 parent a4f9725 commit 7cc71ac

File tree

1 file changed

+23
-31
lines changed

1 file changed

+23
-31
lines changed

src/core/Action.ts

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,6 @@ import {
1414
import type Ros from "./Ros.ts";
1515
import { v4 as uuidv4 } from "uuid";
1616

17-
export class GoalError extends Error {
18-
constructor(status: GoalStatus | number | string, baseError?: unknown) {
19-
const base = typeof baseError === "string" ? baseError : "";
20-
let message: string;
21-
22-
switch (status) {
23-
case GoalStatus.STATUS_CANCELED:
24-
message = `Action was canceled${base ? `: ${base}` : ""}`;
25-
break;
26-
case GoalStatus.STATUS_ABORTED:
27-
message = `Action was aborted${base ? `: ${base}` : ""}`;
28-
break;
29-
case GoalStatus.STATUS_CANCELING:
30-
message = `Action is canceling${base ? `: ${base}` : ""}`;
31-
break;
32-
case GoalStatus.STATUS_UNKNOWN:
33-
message = `Action status unknown${base ? `: ${base}` : ""}`;
34-
break;
35-
default:
36-
message = `Action failed with status ${String(status)}${base ? `: ${base}` : ""}`;
37-
}
38-
39-
super(message);
40-
this.name = "GoalError";
41-
Object.setPrototypeOf(this, GoalError.prototype);
42-
}
43-
}
44-
4517
/**
4618
* A ROS 2 action client.
4719
*/
@@ -101,12 +73,32 @@ export default class Action<
10173
if (isRosbridgeActionResultMessage<TResult>(message)) {
10274
const status = message.status as GoalStatus;
10375

104-
// Validates both status and result
76+
// Check status code instead of result field to properly handle STATUS_CANCELED
10577
if (status === GoalStatus.STATUS_SUCCEEDED && message.result) {
10678
resultCallback(message.values);
10779
} else {
108-
const errorMessage: GoalError = new GoalError(status, message.values);
109-
failedCallback(String(errorMessage));
80+
const baseError =
81+
typeof message.values === "string" ? message.values : "";
82+
83+
let errorMessage: string;
84+
switch (status) {
85+
case GoalStatus.STATUS_CANCELED:
86+
errorMessage = `Action was canceled${baseError ? `: ${baseError}` : ""}`;
87+
break;
88+
case GoalStatus.STATUS_ABORTED:
89+
errorMessage = `Action was aborted${baseError ? `: ${baseError}` : ""}`;
90+
break;
91+
case GoalStatus.STATUS_CANCELING:
92+
errorMessage = `Action is canceling${baseError ? `: ${baseError}` : ""}`;
93+
break;
94+
case GoalStatus.STATUS_UNKNOWN:
95+
errorMessage = `Action status unknown${baseError ? `: ${baseError}` : ""}`;
96+
break;
97+
default:
98+
errorMessage = `Action failed with status ${String(status)}${baseError ? `: ${baseError}` : ""}`;
99+
}
100+
101+
failedCallback(errorMessage);
110102
}
111103
} else if (isRosbridgeActionFeedbackMessage<TFeedback>(message)) {
112104
feedbackCallback?.(message.values);

0 commit comments

Comments
 (0)