fix: Gestione degli errori

Si è aggiornato l'handler degli errori, sostituendo JSONAPI.RequestError con ResponseError di Spraypaint in AddEditRecordDialog. Inoltre, si è rimodellata la gestione dell'errore in onSaveError adattandola alla risposta di Spraypaint.
Il file request.d.ts è stato rinominato in spraypaint.d.ts e il suo contenuto è stato semplificato, esportando direttamente da 'spraypaint'. Infine, si è aggiornato l'index per importare il nuovo file spraypaint.d.ts.
This commit is contained in:
Maicol Battistini 2023-12-11 10:49:10 +01:00
parent 71b03c14b6
commit 3f20852d01
No known key found for this signature in database
4 changed files with 12 additions and 38 deletions

View File

@ -21,6 +21,8 @@ import {
import Stream from 'mithril/stream'; import Stream from 'mithril/stream';
import {Form} from 'mithril-utilities'; import {Form} from 'mithril-utilities';
import {Class} from 'type-fest'; import {Class} from 'type-fest';
import {JsonapiErrorDoc} from 'spraypaint';
import {ResponseError} from 'spraypaint/lib-esm/request';
export default abstract class AddEditRecordDialog<M extends Model> extends RecordDialog<M> { export default abstract class AddEditRecordDialog<M extends Model> extends RecordDialog<M> {
// eslint-disable-next-line unicorn/no-null // eslint-disable-next-line unicorn/no-null
@ -132,7 +134,7 @@ export default abstract class AddEditRecordDialog<M extends Model> extends Recor
this.afterSave(result); this.afterSave(result);
return result; return result;
} catch (error) { } catch (error) {
this.onSaveError(error as JSONAPI.RequestError); this.onSaveError(error as ResponseError);
return false; return false;
} }
} }
@ -143,8 +145,8 @@ export default abstract class AddEditRecordDialog<M extends Model> extends Recor
} }
} }
onSaveError(error: JSONAPI.RequestError): void { async onSaveError(error: ResponseError) {
const {message} = error.response.data; const {message} = (await error.response!.json()) as JsonapiErrorDoc;
void showSnackbar(message, false); void showSnackbar(message, false);
} }

View File

@ -1,4 +1,4 @@
import './global'; import './global';
import './jsx'; import './jsx';
import './modules'; import './modules';
import './request'; import './spraypaint';

View File

@ -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
}
};
}
}

6
resources/ts/typings/spraypaint.d.ts vendored Normal file
View File

@ -0,0 +1,6 @@
export * from 'spraypaint';
module 'spraypaint' {
interface JsonapiErrorDoc {
message: string;
}
}