mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-23 16:13:50 +00:00
working calendar ranges with a subset of features
This commit is contained in:
@@ -20,7 +20,11 @@ export interface FetchParams {
|
||||
[K: string]: string|number|null;
|
||||
};
|
||||
|
||||
export interface ValidationExceptionInterface {
|
||||
export interface TransportExceptionInterface {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface ValidationExceptionInterface extends TransportExceptionInterface {
|
||||
name: 'ValidationException';
|
||||
error: object;
|
||||
violations: string[];
|
||||
@@ -28,18 +32,27 @@ export interface ValidationExceptionInterface {
|
||||
propertyPaths: string[];
|
||||
}
|
||||
|
||||
export interface ValidationErrorResponse {
|
||||
export interface ValidationErrorResponse extends TransportExceptionInterface {
|
||||
violations: {
|
||||
title: string;
|
||||
propertyPath: string;
|
||||
}[];
|
||||
}
|
||||
|
||||
export interface AccessExceptionInterface {
|
||||
export interface AccessExceptionInterface extends TransportExceptionInterface {
|
||||
name: 'AccessException';
|
||||
violations: string[];
|
||||
}
|
||||
|
||||
export interface NotFoundExceptionInterface extends TransportExceptionInterface {
|
||||
name: 'NotFoundException';
|
||||
}
|
||||
|
||||
export interface ServerExceptionInterface extends TransportExceptionInterface {
|
||||
name: 'ServerException';
|
||||
message: string;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generic api method that can be adapted to any fetch request
|
||||
@@ -115,8 +128,16 @@ function _fetchAction<T>(page: number, uri: string, params?: FetchParams): Promi
|
||||
},
|
||||
}).then((response) => {
|
||||
if (response.ok) { return response.json(); }
|
||||
throw new Error(response.statusText);
|
||||
});
|
||||
if (response.status === 404) {
|
||||
throw NotFoundException(response);
|
||||
}
|
||||
|
||||
console.error(response);
|
||||
throw ServerException();
|
||||
}).catch((reason: any) => {
|
||||
console.error(reason);
|
||||
throw ServerException();
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchResults = async<T> (uri: string, params?: FetchParams): Promise<T[]> => {
|
||||
@@ -130,7 +151,8 @@ export const fetchResults = async<T> (uri: string, params?: FetchParams): Promis
|
||||
do {
|
||||
page = ++page;
|
||||
promises.push(
|
||||
_fetchAction<T>(page, uri, params).then(r => Promise.resolve(r.results))
|
||||
_fetchAction<T>(page, uri, params)
|
||||
.then(r => Promise.resolve(r.results))
|
||||
);
|
||||
} while (page * firstData.pagination.items_per_page < firstData.count)
|
||||
}
|
||||
@@ -162,3 +184,17 @@ const AccessException = (response: Response): AccessExceptionInterface => {
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
const NotFoundException = (response: Response): NotFoundExceptionInterface => {
|
||||
const error = {} as NotFoundExceptionInterface;
|
||||
error.name = 'NotFoundException';
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
const ServerException = (): ServerExceptionInterface => {
|
||||
const error = {} as ServerExceptionInterface;
|
||||
error.name = 'ServerException';
|
||||
|
||||
return error;
|
||||
}
|
||||
|
Reference in New Issue
Block a user