Skip to content

Commit 9ea19f6

Browse files
committed
Accept more than just Matrix API error details
As long as the error details payload is extensible, let drivers put more data in them than just the key for Matrix API error responses.
1 parent fc48df3 commit 9ea19f6

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

src/ClientWidgetApi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,11 +833,11 @@ export class ClientWidgetApi extends EventEmitter {
833833
}
834834

835835
private handleDriverError(e: unknown, request: IWidgetApiRequest, message: string) {
836-
const matrixApiError = this.driver.processError(e);
836+
const errorDetails = this.driver.processError(e);
837837
this.transport.reply<IWidgetApiErrorResponseData>(request, {
838838
error: {
839839
message,
840-
...(matrixApiError && { matrix_api_error: { ...matrixApiError } }),
840+
...errorDetails,
841841
},
842842
});
843843
}

src/driver/WidgetDriver.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import {
1919
IOpenIDCredentials,
2020
OpenIDRequestState,
2121
SimpleObservable,
22-
IMatrixApiError,
2322
IRoomEvent,
2423
IRoomAccountData,
2524
ITurnServer,
25+
IWidgetApiErrorResponseDataDetails,
2626
UpdateDelayedEventAction,
2727
} from "..";
2828

@@ -361,13 +361,12 @@ export abstract class WidgetDriver {
361361
}
362362

363363
/**
364-
* Expresses an error thrown by a Matrix API request made by this driver
365-
* in a format compatible with the Widget API.
364+
* Expresses an error thrown by this driver in a format compatible with the Widget API.
366365
* @param error The error to handle.
367-
* @returns The error expressed as a {@link IMatrixApiError},
366+
* @returns The error expressed as a {@link IWidgetApiErrorResponseDataDetails},
368367
* or undefined if it cannot be expressed as one.
369368
*/
370-
public processError(error: unknown): IMatrixApiError | undefined {
369+
public processError(error: unknown): IWidgetApiErrorResponseDataDetails | undefined {
371370
return undefined;
372371
}
373372
}

test/ClientWidgetApi-test.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
ISendEventFromWidgetActionRequest,
3737
IUpdateDelayedEventFromWidgetActionRequest,
3838
IUploadFileActionFromWidgetActionRequest,
39+
IWidgetApiErrorResponseDataDetails,
3940
UpdateDelayedEventAction,
4041
} from '../src';
4142
import { IGetMediaConfigActionFromWidgetActionRequest } from '../src/interfaces/GetMediaConfigAction';
@@ -70,15 +71,17 @@ class CustomMatrixError extends Error {
7071
}
7172
}
7273

73-
function processCustomMatrixError(e: unknown): IMatrixApiError | undefined {
74+
function processCustomMatrixError(e: unknown): IWidgetApiErrorResponseDataDetails | undefined {
7475
return e instanceof CustomMatrixError ? {
75-
http_status: e.httpStatus,
76-
http_headers: {},
77-
url: '',
78-
response: {
79-
errcode: e.name,
80-
error: e.message,
81-
...e.data,
76+
matrix_api_error: {
77+
http_status: e.httpStatus,
78+
http_headers: {},
79+
url: '',
80+
response: {
81+
errcode: e.name,
82+
error: e.message,
83+
...e.data,
84+
},
8285
},
8386
} : undefined;
8487
}

0 commit comments

Comments
 (0)