From 27e7f71d4893eb9e7e9640edfba7f4ae74e83811 Mon Sep 17 00:00:00 2001 From: Ro0t-set Date: Fri, 24 May 2024 14:23:01 +0200 Subject: [PATCH] fix(api): change error property to message --- frontend-service/src/main/vue/api/errors.ts | 6 +-- .../src/main/vue/api/messages/channel.ts | 12 +++--- .../src/main/vue/api/messages/direct.ts | 6 +-- .../src/main/vue/api/piperchat/channel.ts | 32 ++++++++-------- .../src/main/vue/api/piperchat/server.ts | 38 +++++++++---------- frontend-service/src/main/vue/api/response.ts | 2 +- .../src/main/vue/api/users/auth.ts | 12 +++--- .../src/main/vue/api/users/friends.ts | 24 ++++++------ .../src/main/vue/api/users/user.ts | 6 +-- .../main/vue/controllers/axios-controller.ts | 5 ++- .../src/main/vue/stores/friend.ts | 6 +-- .../src/main/vue/stores/server.ts | 16 ++++---- frontend-service/src/main/vue/stores/user.ts | 4 +- 13 files changed, 86 insertions(+), 83 deletions(-) diff --git a/frontend-service/src/main/vue/api/errors.ts b/frontend-service/src/main/vue/api/errors.ts index 2981719a2..e40a216fd 100644 --- a/frontend-service/src/main/vue/api/errors.ts +++ b/frontend-service/src/main/vue/api/errors.ts @@ -2,7 +2,7 @@ import { ErrorResponse } from "./response"; export class InternalServerError extends ErrorResponse { statusCode = 500; - error = "Internal Server Error" as const; + message = "Internal Server Error" as const; errorMessage: unknown; constructor(e: unknown = "") { super(); @@ -12,7 +12,7 @@ export class InternalServerError extends ErrorResponse { export class BadRequest extends ErrorResponse { statusCode = 400; - error = "Bad Request" as const; + message = "Bad Request" as const; missingParams: string[]; missingBody: string[]; missingQuery?: string[]; @@ -26,5 +26,5 @@ export class BadRequest extends ErrorResponse { export class JwtTokenMissingOrInvalid extends ErrorResponse { statusCode = 401; - error = "JWT Token Missing or Invalid" as const; + message = "JWT Token Missing or Invalid" as const; } diff --git a/frontend-service/src/main/vue/api/messages/channel.ts b/frontend-service/src/main/vue/api/messages/channel.ts index 5fa79b58e..9d44316e4 100644 --- a/frontend-service/src/main/vue/api/messages/channel.ts +++ b/frontend-service/src/main/vue/api/messages/channel.ts @@ -44,16 +44,16 @@ export module GetChannelMessagesApi { export module Errors { export class ChannelNotFound extends ErrorResponse { statusCode = 404; - error = "Channel not found" as const; + message = "Channel not found" as const; } export class ServerNotFound extends ErrorResponse { statusCode = 404; - error = "Server not found" as const; + message = "Server not found" as const; } export class UserNotAuthorized extends ErrorResponse { statusCode = 403; - error = "User not authorized" as const; + message = "User not authorized" as const; } export type Type = ChannelNotFound | ServerNotFound | UserNotAuthorized; @@ -91,15 +91,15 @@ export module SendMessageInChannelApi { export module Errors { export class ChannelNotFound extends ErrorResponse { statusCode = 404; - error = "Channel not found" as const; + message = "Channel not found" as const; } export class ServerNotFound extends ErrorResponse { statusCode = 404; - error = "Server not found" as const; + message = "Server not found" as const; } export class UserNotAuthorized extends ErrorResponse { statusCode = 403; - error = "User not authorized" as const; + message = "User not authorized" as const; } export type Type = ChannelNotFound | ServerNotFound | UserNotAuthorized; } diff --git a/frontend-service/src/main/vue/api/messages/direct.ts b/frontend-service/src/main/vue/api/messages/direct.ts index a92bff1da..f73a4961d 100644 --- a/frontend-service/src/main/vue/api/messages/direct.ts +++ b/frontend-service/src/main/vue/api/messages/direct.ts @@ -42,7 +42,7 @@ export module GetDirectMessagesApi { export module Errors { export class DirectNotFound extends ErrorResponse { statusCode = 404; - error = "Direct not found" as const; + message = "Direct not found" as const; } export type Type = DirectNotFound; } @@ -78,11 +78,11 @@ export module SendDirectMessageApi { export module Errors { export class DirectNotFound extends ErrorResponse { statusCode = 404; - error = "Direct not found" as const; + message = "Direct not found" as const; } export class CannotSendDirectMessageToYourself extends ErrorResponse { statusCode = 400; - error = "Cannot send direct message to yourself" as const; + message = "Cannot send direct message to yourself" as const; } export type Type = DirectNotFound | CannotSendDirectMessageToYourself; } diff --git a/frontend-service/src/main/vue/api/piperchat/channel.ts b/frontend-service/src/main/vue/api/piperchat/channel.ts index f1253c4fb..504cdab21 100644 --- a/frontend-service/src/main/vue/api/piperchat/channel.ts +++ b/frontend-service/src/main/vue/api/piperchat/channel.ts @@ -38,12 +38,12 @@ export module GetChannelsApi { export module Errors { export class ServerNotFound extends ErrorResponse { statusCode = 404; - error = "Server not found" as const; + message = "Server not found" as const; } export class UserNotAuthorized extends ErrorResponse { statusCode = 403; - error = "User not authorized" as const; + message = "User not authorized" as const; } export type Type = ServerNotFound | UserNotAuthorized; @@ -88,17 +88,17 @@ export module GetChannelByIdApi { export module Errors { export class ChannelNotFound extends ErrorResponse { statusCode = 404; - error = "Channel not found" as const; + message = "Channel not found" as const; } export class UserNotAuthorized extends ErrorResponse { statusCode = 403; - error = "User not authorized" as const; + message = "User not authorized" as const; } export class ServerNotFound extends ErrorResponse { statusCode = 404; - error = "Server not found" as const; + message = "Server not found" as const; } export type Type = ChannelNotFound | UserNotAuthorized | ServerNotFound; @@ -158,22 +158,22 @@ export module CreateChannelApi { export module Errors { export class ServerNotFound extends ErrorResponse { statusCode = 404; - error = "Server not found" as const; + message = "Server not found" as const; } export class UserNotAuthorized extends ErrorResponse { statusCode = 403; - error = "User not authorized" as const; + message = "User not authorized" as const; } export class ChannelAlreadyExists extends ErrorResponse { statusCode = 409; - error = "Channel already exists" as const; + message = "Channel already exists" as const; } export class InvalidChannelType extends ErrorResponse { statusCode = 400; - error = "Invalid channel type" as const; + message = "Invalid channel type" as const; } export type Type = @@ -218,22 +218,22 @@ export module UpdateChannelApi { export module Errors { export class ServerNotFound extends ErrorResponse { statusCode = 404; - error = "Server not found" as const; + message = "Server not found" as const; } export class ChannelNotFound extends ErrorResponse { statusCode = 404; - error = "Channel not found" as const; + message = "Channel not found" as const; } export class UserNotAuthorized extends ErrorResponse { statusCode = 403; - error = "User not authorized" as const; + message = "User not authorized" as const; } export class ChannelAlreadyExists extends ErrorResponse { statusCode = 409; - error = "Channel already exists" as const; + message = "Channel already exists" as const; } export type Type = @@ -272,17 +272,17 @@ export module DeleteChannelApi { export module Errors { export class ServerNotFound extends ErrorResponse { statusCode = 404; - error = "Server not found" as const; + message = "Server not found" as const; } export class ChannelNotFound extends ErrorResponse { statusCode = 404; - error = "Channel not found" as const; + message = "Channel not found" as const; } export class UserNotAuthorized extends ErrorResponse { statusCode = 403; - error = "User not authorized" as const; + message = "User not authorized" as const; } export type Type = ServerNotFound | ChannelNotFound | UserNotAuthorized; diff --git a/frontend-service/src/main/vue/api/piperchat/server.ts b/frontend-service/src/main/vue/api/piperchat/server.ts index 23b39235c..b916747c8 100644 --- a/frontend-service/src/main/vue/api/piperchat/server.ts +++ b/frontend-service/src/main/vue/api/piperchat/server.ts @@ -27,15 +27,15 @@ export module KickUserFromServerApi { export module Errors { export class ServerNotFound extends ErrorResponse { statusCode = 404; - error = "Server or user not found" as const; + message = "Server or user not found" as const; } export class UserNotAuthorized extends ErrorResponse { statusCode = 403; - error = "User not authorized" as const; + message = "User not authorized" as const; } export class OwnerCannotLeave extends ErrorResponse { statusCode = 405; - error = "Owner cannot leave the server" as const; + message = "Owner cannot leave the server" as const; } export type Type = ServerNotFound | UserNotAuthorized | OwnerCannotLeave; } @@ -68,11 +68,11 @@ export module GetServerParticipantsApi { export module Errors { export class ServerNotFound extends ErrorResponse { statusCode = 404; - error = "Server not found" as const; + message = "Server not found" as const; } export class UserNotAuthorized extends ErrorResponse { statusCode = 403; - error = "User not authorized" as const; + message = "User not authorized" as const; } export type Type = ServerNotFound | UserNotAuthorized; } @@ -103,11 +103,11 @@ export module JoinServerApi { export module Errors { export class ServerNotFound extends ErrorResponse { statusCode = 404; - error = "Server not found" as const; + message = "Server not found" as const; } export class UserAlreadyJoined extends ErrorResponse { statusCode = 403; - error = "User already joined" as const; + message = "User already joined" as const; } export type Type = ServerNotFound | UserAlreadyJoined; } @@ -138,15 +138,15 @@ export module LeaveServerApi { export module Errors { export class ServerNotFound extends ErrorResponse { statusCode = 404; - error = "Server not found" as const; + message = "Server not found" as const; } export class UserNotInServer extends ErrorResponse { statusCode = 403; - error = "User not in server" as const; + message = "User not in server" as const; } export class OwnerCannotLeave extends ErrorResponse { statusCode = 422; - error = "Owner cannot leave the server" as const; + message = "Owner cannot leave the server" as const; } export type Type = ServerNotFound | UserNotInServer | OwnerCannotLeave; } @@ -193,11 +193,11 @@ export module GetServerApi { export module Errors { export class ServerNotFound extends ErrorResponse { statusCode = 404; - error = "Server not found" as const; + message = "Server not found" as const; } export class UserNotAuthorized extends ErrorResponse { statusCode = 403; - error = "User not authorized" as const; + message = "User not authorized" as const; } export type Type = ServerNotFound | UserNotAuthorized; } @@ -234,15 +234,15 @@ export module UpdateServerApi { export module Errors { export class ServerNotFound extends ErrorResponse { statusCode = 404; - error = "Server not found" as const; + message = "Server not found" as const; } export class UserNotAuthorized extends ErrorResponse { statusCode = 403; - error = "User not authorized" as const; + message = "User not authorized" as const; } export class NameOrDescriptionRequired extends ErrorResponse { statusCode = 422; - error = "Name or description required" as const; + message = "Name or description required" as const; } export type Type = ServerNotFound | UserNotAuthorized; } @@ -273,11 +273,11 @@ export module DeleteServerApi { export module Errors { export class ServerNotFound extends ErrorResponse { statusCode = 404; - error = "Server not found" as const; + message = "Server not found" as const; } export class UserNotAuthorized extends ErrorResponse { statusCode = 403; - error = "User not authorized" as const; + message = "User not authorized" as const; } export type Type = ServerNotFound | UserNotAuthorized; } @@ -322,7 +322,7 @@ export module GetServersApi { export module Errors { export class UserNotFound extends ErrorResponse { statusCode = 404; - error = "User not found" as const; + message = "User not found" as const; } export type Type = UserNotFound; } @@ -360,7 +360,7 @@ export module CreateServerApi { export module Errors { export class NameOrDescriptionRequired extends ErrorResponse { statusCode = 422; - error = "Name or description required" as const; + message = "Name or description required" as const; } export type Type = NameOrDescriptionRequired; } diff --git a/frontend-service/src/main/vue/api/response.ts b/frontend-service/src/main/vue/api/response.ts index 3fb4a95f8..24f41ad5f 100644 --- a/frontend-service/src/main/vue/api/response.ts +++ b/frontend-service/src/main/vue/api/response.ts @@ -16,5 +16,5 @@ export abstract class Response { } export abstract class ErrorResponse extends Response { - abstract error: string; + abstract message: string; } diff --git a/frontend-service/src/main/vue/api/users/auth.ts b/frontend-service/src/main/vue/api/users/auth.ts index c46c07293..bcef27ff6 100644 --- a/frontend-service/src/main/vue/api/users/auth.ts +++ b/frontend-service/src/main/vue/api/users/auth.ts @@ -61,12 +61,12 @@ export module RegisterApi { export module Errors { export class UserAlreadyExists extends ErrorResponse { statusCode = 409; - error = "User already exists" as const; + message = "User already exists" as const; } export class EmailAlreadyExists extends ErrorResponse { statusCode = 409; - error = "Email already exists" as const; + message = "Email already exists" as const; } export type Type = UserAlreadyExists | EmailAlreadyExists; @@ -116,7 +116,7 @@ export module LoginApi { export module Errors { export class UsernameOrPasswordIncorrect extends ErrorResponse { statusCode = 401; - error = "Username or password incorrect" as const; + message = "Username or password incorrect" as const; } export type Type = UsernameOrPasswordIncorrect; } @@ -149,7 +149,7 @@ export module LogoutApi { export module Errors { export class UserNotFound extends ErrorResponse { statusCode = 404; - error = "User not found" as const; + message = "User not found" as const; } export type Type = UserNotFound; } @@ -185,11 +185,11 @@ export module RefreshTokenApi { export module Errors { export class UserNotFound extends ErrorResponse { statusCode = 404; - error = "User not found" as const; + message = "User not found" as const; } export class InvalidRefreshToken extends ErrorResponse { statusCode = 401; - error = "Refresh token is missing or invalid" as const; + message = "Refresh token is missing or invalid" as const; } export type Type = UserNotFound | InvalidRefreshToken; } diff --git a/frontend-service/src/main/vue/api/users/friends.ts b/frontend-service/src/main/vue/api/users/friends.ts index c895f862e..177b19241 100644 --- a/frontend-service/src/main/vue/api/users/friends.ts +++ b/frontend-service/src/main/vue/api/users/friends.ts @@ -23,7 +23,7 @@ export module GetFriendsApi { export module Errors { export class UserNotFound extends ErrorResponse { statusCode = 404; - error = "User not found" as const; + message = "User not found" as const; } export type Type = UserNotFound; } @@ -51,7 +51,7 @@ export module GetFriendsRequestsApi { export module Errors { export class UserNotFound extends ErrorResponse { statusCode = 404; - error = "User not found" as const; + message = "User not found" as const; } export type Type = UserNotFound; } @@ -83,19 +83,19 @@ export module SendFriendRequestApi { export module Errors { export class InvalidAction extends ErrorResponse { statusCode = 400; - error: string; + message: string; constructor(action: string) { super(); - this.error = `Invalid 'action' parameter in body: '${action}'`; + this.message = `Invalid 'action' parameter in body: '${action}'`; } } export class FriendRequestAlreadySent extends ErrorResponse { statusCode = 409; - error = "Friend request already sent" as const; + message = "Friend request already sent" as const; } export class FriendRequestNotFound extends ErrorResponse { statusCode = 404; - error = "Friend request not found" as const; + message = "Friend request not found" as const; } export type Type = @@ -131,15 +131,15 @@ export module AcceptFriendRequestApi { export module Errors { export class InvalidAction extends ErrorResponse { statusCode = 400; - error: string; + message: string; constructor(action: string) { super(); - this.error = `Invalid 'action' parameter in body: '${action}'`; + this.message = `Invalid 'action' parameter in body: '${action}'`; } } export class FriendRequestNotFound extends ErrorResponse { statusCode = 404; - error = "Friend request not found" as const; + message = "Friend request not found" as const; } export type Type = FriendRequestNotFound; @@ -172,16 +172,16 @@ export module DeclineFriendRequestApi { export module Errors { export class InvalidAction extends ErrorResponse { statusCode = 400; - error: string; + message: string; constructor(action: string) { super(); - this.error = `Invalid 'action' parameter in body: '${action}'`; + this.message = `Invalid 'action' parameter in body: '${action}'`; } } export class FriendRequestNotFound extends ErrorResponse { statusCode = 404; - error = "Friend request not found" as const; + message = "Friend request not found" as const; } export type Type = InvalidAction | FriendRequestNotFound; diff --git a/frontend-service/src/main/vue/api/users/user.ts b/frontend-service/src/main/vue/api/users/user.ts index 6df8dcb8a..fab71a7d8 100644 --- a/frontend-service/src/main/vue/api/users/user.ts +++ b/frontend-service/src/main/vue/api/users/user.ts @@ -71,7 +71,7 @@ export module GetUserStatusApi { export module Errors { export class UserNotFound extends ErrorResponse { statusCode = 404; - error = "User not found" as const; + message = "User not found" as const; } export type Type = UserNotFound; } @@ -109,7 +109,7 @@ export module GetUserPhotoApi { export module Errors { export class UserNotFound extends ErrorResponse { statusCode = 404; - error = "User not found" as const; + message = "User not found" as const; } export type Type = UserNotFound; } @@ -147,7 +147,7 @@ export module GetUserDescriptionApi { export module Errors { export class UserNotFound extends ErrorResponse { statusCode = 404; - error = "User not found" as const; + message = "User not found" as const; } export type Type = UserNotFound; } diff --git a/frontend-service/src/main/vue/controllers/axios-controller.ts b/frontend-service/src/main/vue/controllers/axios-controller.ts index 22080b9c4..d3e4d1bf5 100644 --- a/frontend-service/src/main/vue/controllers/axios-controller.ts +++ b/frontend-service/src/main/vue/controllers/axios-controller.ts @@ -39,7 +39,10 @@ export abstract class AxiosController { const errorResponse = e.response.data as InternalServerError; throw new Error(errorResponse.toString()); } else { - return e.response.data as Response; + return { + statusCode: e.response.status, + ...e.response.data, + } as Response; } } } diff --git a/frontend-service/src/main/vue/stores/friend.ts b/frontend-service/src/main/vue/stores/friend.ts index bd3875f6d..e50ed6b59 100644 --- a/frontend-service/src/main/vue/stores/friend.ts +++ b/frontend-service/src/main/vue/stores/friend.ts @@ -63,7 +63,7 @@ export const useFriendStore = defineStore( const response = await friendsController.sendFriendRequest(username); if (response.statusCode !== 200) { const typed = response as DeclineFriendRequestApi.Errors.Type; - throw new Error(typed.error); + throw new Error(typed.message); } } @@ -73,7 +73,7 @@ export const useFriendStore = defineStore( await refresh(); } else { const typed = response as DeclineFriendRequestApi.Errors.Type; - throw new Error(typed.error); + throw new Error(typed.message); } } @@ -83,7 +83,7 @@ export const useFriendStore = defineStore( await refresh(); } else { const typed = response as DeclineFriendRequestApi.Errors.Type; - throw new Error(typed.error); + throw new Error(typed.message); } } diff --git a/frontend-service/src/main/vue/stores/server.ts b/frontend-service/src/main/vue/stores/server.ts index 0adabaa4e..73e67d5d8 100644 --- a/frontend-service/src/main/vue/stores/server.ts +++ b/frontend-service/src/main/vue/stores/server.ts @@ -86,7 +86,7 @@ export const useServerStore = defineStore( await refresh(); } else { const typed = response as CreateServerApi.Errors.Type; - throw new Error(String(typed.error)); + throw new Error(String(typed.message)); } } @@ -106,7 +106,7 @@ export const useServerStore = defineStore( await refresh(); } else { const typed = response as CreateChannelApi.Errors.Type; - throw new Error(String(typed.error)); + throw new Error(String(typed.message)); } } @@ -116,7 +116,7 @@ export const useServerStore = defineStore( await refresh(); } else { const typed = response as JoinServerApi.Errors.Type; - throw new Error(String(typed.error)); + throw new Error(String(typed.message)); } } @@ -126,7 +126,7 @@ export const useServerStore = defineStore( await refresh(); } else { const typed = response as JoinServerApi.Errors.Type; - throw new Error(String(typed.error)); + throw new Error(String(typed.message)); } } @@ -139,7 +139,7 @@ export const useServerStore = defineStore( await refresh(); } else { const typed = response as KickUserFromServerApi.Errors.Type; - throw new Error(String(typed.error)); + throw new Error(String(typed.message)); } } @@ -152,7 +152,7 @@ export const useServerStore = defineStore( await refresh(); } else { const typed = response as KickUserFromServerApi.Errors.Type; - throw new Error(String(typed.error)); + throw new Error(String(typed.message)); } } @@ -170,7 +170,7 @@ export const useServerStore = defineStore( await refresh(); } else { const typed = response as UpdateServerApi.Errors.Type; - throw new Error(String(typed.error)); + throw new Error(String(typed.message)); } } @@ -190,7 +190,7 @@ export const useServerStore = defineStore( await refresh(); } else { const typed = response as UpdateServerApi.Errors.Type; - throw new Error(String(typed.error)); + throw new Error(String(typed.message)); } } diff --git a/frontend-service/src/main/vue/stores/user.ts b/frontend-service/src/main/vue/stores/user.ts index 60f7b92b8..f3f49b848 100644 --- a/frontend-service/src/main/vue/stores/user.ts +++ b/frontend-service/src/main/vue/stores/user.ts @@ -42,7 +42,7 @@ export const useUserStore = defineStore( jwt.value = (response as LoginApi.Responses.Success).access_token; } else { const typed = response as LoginApi.Errors.Type; - throw new Error(typed.error); + throw new Error(typed.message); } } @@ -58,7 +58,7 @@ export const useUserStore = defineStore( }); if (response.statusCode !== 200) { const typed = response as RegisterApi.Errors.Type; - throw new Error(typed.error); + throw new Error(typed.message); } }