Skip to content

Commit 1a6f735

Browse files
tweak: switch around getMessage params of ErrorEntry
1 parent 570c53a commit 1a6f735

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@povio/openapi-codegen-cli",
3-
"version": "2.0.2-rc.0",
3+
"version": "2.0.2-rc.1",
44
"main": "./dist/index.js",
55
"types": "./dist/index.d.ts",
66
"exports": {

src/lib/rest/error-handling.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class ApplicationException<CodeT> extends Error {
2828
export interface ErrorEntry<CodeT> {
2929
code: CodeT;
3030
condition?: (error: unknown) => boolean;
31-
getMessage: (error: unknown, t: TFunction) => string;
31+
getMessage: (t: TFunction, error: unknown) => string;
3232
}
3333

3434
export interface ErrorHandlerOptions<CodeT extends string> {
@@ -98,7 +98,14 @@ export class ErrorHandler<CodeT extends string> {
9898
const unknownError: ErrorEntry<ICodeT> = {
9999
code: "UNKNOWN_ERROR",
100100
condition: () => true,
101-
getMessage: () => this.t("openapi.sharedErrors.unknownError"),
101+
getMessage: (e) => {
102+
if (axios.isAxiosError(e) && e.response?.data?.code) {
103+
return this.t("openapi.sharedErrors.unknownErrorWithCode", {
104+
code: e.response.data.code,
105+
});
106+
}
107+
return this.t("openapi.sharedErrors.unknownError");
108+
},
102109
};
103110

104111
// general errors have the lowest priority
@@ -121,7 +128,7 @@ export class ErrorHandler<CodeT extends string> {
121128
const errorEntry = this.entries.find((entry) => this.matchesEntry(error, entry, code))!;
122129

123130
const serverMessage = RestUtils.extractServerErrorMessage(error);
124-
const exception = new ApplicationException(errorEntry.getMessage(error, this.t), errorEntry.code, serverMessage);
131+
const exception = new ApplicationException(errorEntry.getMessage(this.t, error), errorEntry.code, serverMessage);
125132

126133
this.onRethrowError?.(error, exception);
127134

0 commit comments

Comments
 (0)