Skip to content

Commit

Permalink
#12 - Remove deprecatedErrorObject
Browse files Browse the repository at this point in the history
  • Loading branch information
kristianbinau committed Oct 2, 2023
1 parent 975b42c commit a0cf399
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 49 deletions.
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

0 comments on commit a0cf399

Please sign in to comment.