fix registration
This commit is contained in:
parent
2ec9354fc1
commit
08f827267d
12 changed files with 84 additions and 88 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import {BASE_URL, createRequestConfig, handleResponse} from "./BaseApi.ts";
|
||||
import {BASE_URL, createRequestConfig, handleResponse, handleUnauthorizedError} from "./BaseApi.ts";
|
||||
|
||||
export interface ISurvey {
|
||||
id: number;
|
||||
|
|
@ -28,6 +28,7 @@ export const getMySurveys = async (): Promise<ISurvey[]> => {
|
|||
});
|
||||
return await handleResponse(response);
|
||||
} catch (error) {
|
||||
handleUnauthorizedError(error);
|
||||
console.error("Error receiving surveys:", error);
|
||||
throw error;
|
||||
}
|
||||
|
|
@ -43,6 +44,7 @@ export const getAllSurveys = async (): Promise<ISurvey[]> => {
|
|||
})
|
||||
return await handleResponse(response);
|
||||
} catch (error) {
|
||||
handleUnauthorizedError(error);
|
||||
console.error("Error receiving surveys:", error);
|
||||
throw error;
|
||||
}
|
||||
|
|
@ -68,12 +70,13 @@ export const postNewSurvey = async (survey: INewSurvey): Promise<ISurvey> => {
|
|||
throw new Error(`Ошибка: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
const data = await handleResponse(response);
|
||||
if (!data.id) {
|
||||
throw new Error("Сервер не вернул ID опроса");
|
||||
}
|
||||
return data;
|
||||
} catch (error) {
|
||||
handleUnauthorizedError(error);
|
||||
console.error(`Error when adding a new survey: ${error}`);
|
||||
throw error;
|
||||
}
|
||||
|
|
@ -90,6 +93,7 @@ export const getSurveyById = async (surveyId: number): Promise<ISurvey> => {
|
|||
})
|
||||
return await handleResponse(response);
|
||||
} catch (error){
|
||||
handleUnauthorizedError(error);
|
||||
console.error(`Error finding the survey by id: ${error}`);
|
||||
throw error;
|
||||
}
|
||||
|
|
@ -115,6 +119,7 @@ export const deleteSurvey = async (surveyId: number) => {
|
|||
}
|
||||
return responseData;
|
||||
} catch (error){
|
||||
handleUnauthorizedError(error);
|
||||
console.error(`Error deleting a survey: ${error}`);
|
||||
throw error;
|
||||
}
|
||||
|
|
@ -138,12 +143,10 @@ export const updateSurvey = async (surveyId: number, survey: Partial<INewSurvey>
|
|||
description: survey.description,
|
||||
})
|
||||
})
|
||||
if (response.status === 200) {
|
||||
return await handleResponse(response);
|
||||
}
|
||||
throw new Error(`Ожидался код 200, получен ${response.status}`);
|
||||
return await handleResponse(response);
|
||||
}
|
||||
catch (error){
|
||||
handleUnauthorizedError(error);
|
||||
console.error(`Error updating survey: ${error}`);
|
||||
throw error;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue