Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove deprecatedErrorObject #13

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions src/components/FormSignIn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@
<script setup lang="ts">
import BaseInput from './base/input.vue';
import BaseButton, { ButtonColor } from './base/button.vue';
import ErrorAlert, {
type ErrorObject,
isDeprecatedErrorObject,
convertDeprecatedErrorObject,
} from './base/errorAlert.vue';
import ErrorAlert, { type ErrorObject } from './base/errorAlert.vue';

import { asset, api, url } from '@lib/helpers';
import { t } from '@lib/i18n';
Expand Down Expand Up @@ -92,13 +88,7 @@ function onSubmit() {
if (!response.ok) {
if (response.status >= 400 && response.status < 500) {
const json = await response.json();

// Somebody didn't update the backend to return ErrorObjects..
if (isDeprecatedErrorObject(json)) {
errorObject.value = convertDeprecatedErrorObject(json);
} else {
errorObject.value = json as ErrorObject;
}
errorObject.value = json as ErrorObject;

throw new Error(json.error);
}
Expand Down
14 changes: 2 additions & 12 deletions src/components/FormSignUp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,7 @@
<script setup lang="ts">
import BaseInput from './base/input.vue';
import BaseButton, { ButtonColor } from './base/button.vue';
import ErrorAlert, {
type ErrorObject,
isDeprecatedErrorObject,
convertDeprecatedErrorObject,
} from './base/errorAlert.vue';
import ErrorAlert, { type ErrorObject } from './base/errorAlert.vue';

import { t } from '@lib/i18n';
import { asset, api, url } from '@lib/helpers';
Expand Down Expand Up @@ -124,13 +120,7 @@ function onSubmit() {
if (!response.ok) {
if (response.status >= 400 && response.status < 500) {
const json = await response.json();

// Somebody didn't update the backend to return ErrorObjects..
if (isDeprecatedErrorObject(json)) {
errorObject.value = convertDeprecatedErrorObject(json);
} else {
errorObject.value = json as ErrorObject;
}
errorObject.value = json as ErrorObject;

throw new Error(json.error);
}
Expand Down
25 changes: 0 additions & 25 deletions src/components/base/errorAlert.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,6 @@ export type ErrorObject = {
};
statusCode: number;
};

/**
* @deprecated Use ErrorObject instead
*/
export type DeprecatedErrorObject = {
error: string;
message: string;
statusCode: number;
};

export const isDeprecatedErrorObject = (
errorObject: Object,
): errorObject is DeprecatedErrorObject => {
return 'message' in errorObject;
};

export const convertDeprecatedErrorObject = (errorObject: DeprecatedErrorObject): ErrorObject => {
return {
error: errorObject.error,
errors: {
_: [errorObject.message],
},
statusCode: errorObject.statusCode,
};
};
</script>

<script setup lang="ts">
Expand Down