diff --git a/resources/ts/Components/Dialogs/AddEditRecordDialog.tsx b/resources/ts/Components/Dialogs/AddEditRecordDialog.tsx index e7fa4b5c2..7fb32e6c7 100644 --- a/resources/ts/Components/Dialogs/AddEditRecordDialog.tsx +++ b/resources/ts/Components/Dialogs/AddEditRecordDialog.tsx @@ -21,6 +21,8 @@ import { import Stream from 'mithril/stream'; import {Form} from 'mithril-utilities'; import {Class} from 'type-fest'; +import {JsonapiErrorDoc} from 'spraypaint'; +import {ResponseError} from 'spraypaint/lib-esm/request'; export default abstract class AddEditRecordDialog extends RecordDialog { // eslint-disable-next-line unicorn/no-null @@ -132,7 +134,7 @@ export default abstract class AddEditRecordDialog extends Recor this.afterSave(result); return result; } catch (error) { - this.onSaveError(error as JSONAPI.RequestError); + this.onSaveError(error as ResponseError); return false; } } @@ -143,8 +145,8 @@ export default abstract class AddEditRecordDialog extends Recor } } - onSaveError(error: JSONAPI.RequestError): void { - const {message} = error.response.data; + async onSaveError(error: ResponseError) { + const {message} = (await error.response!.json()) as JsonapiErrorDoc; void showSnackbar(message, false); } diff --git a/resources/ts/typings/index.d.ts b/resources/ts/typings/index.d.ts index 1626e8817..f72eb7426 100644 --- a/resources/ts/typings/index.d.ts +++ b/resources/ts/typings/index.d.ts @@ -1,4 +1,4 @@ import './global'; import './jsx'; import './modules'; -import './request'; +import './spraypaint'; diff --git a/resources/ts/typings/request.d.ts b/resources/ts/typings/request.d.ts deleted file mode 100644 index d6305dbc9..000000000 --- a/resources/ts/typings/request.d.ts +++ /dev/null @@ -1,34 +0,0 @@ -export declare namespace JSONAPI { - - export interface Trace { - file: string; - line: number; - function: string; - class: string; - type: string; - } - - export interface Meta { - exception: string; - file: string; - line: number; - trace: Trace[]; - } - - export interface Error { - detail: string; - meta: Meta; - status: string; - title: string; - } - - export interface RequestError { - response: { - // TODO: This is a temporary fix, new model library will be implemented later - data: { - errors: JSONAPI.Error[], - message: string - } - }; - } -} diff --git a/resources/ts/typings/spraypaint.d.ts b/resources/ts/typings/spraypaint.d.ts new file mode 100644 index 000000000..7b0ea9166 --- /dev/null +++ b/resources/ts/typings/spraypaint.d.ts @@ -0,0 +1,6 @@ +export * from 'spraypaint'; +module 'spraypaint' { + interface JsonapiErrorDoc { + message: string; + } +}