Skip to content

Commit

Permalink
replace ouch with built in createError on the client side
Browse files Browse the repository at this point in the history
  • Loading branch information
rizen committed Oct 30, 2024
1 parent 9197710 commit c366b51
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
7 changes: 3 additions & 4 deletions app/composables/ving/useVingKind.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { defu } from "defu";
import { debounce } from 'perfect-debounce';
import { ouch } from '#ving/utils/ouch.mjs';
class VingKind {
#notify = useNotify();

Expand Down Expand Up @@ -265,7 +264,7 @@ class VingKind {
return this.records[index];
}
else {
throw ouch(404, `cannot find "${id}" in record list`);
throw createError({ statusCode: 404, message: `cannot find "${id}" in record list` });
}
}

Expand Down Expand Up @@ -293,7 +292,7 @@ class VingKind {
return this.#behavior.createApi;
}
this.#notify.error('No createApi');
throw ouch(401, 'No createApi');
throw createError({ statusCode: 401, message: 'No createApi' });
}

/**
Expand All @@ -308,7 +307,7 @@ class VingKind {
return this.#behavior.listApi;
}
this.#notify.error('No listApi');
throw ouch(401, 'No listApi');
throw createError({ statusCode: 401, message: 'No listApi' });
}

/**
Expand Down
7 changes: 3 additions & 4 deletions app/composables/ving/useVingRecord.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { defineStore } from 'pinia';
import { defu } from "defu";
import { v4 } from 'uuid';
import { ouch } from '#ving/utils/ouch.mjs';
import { isObject, isUndefined } from '#ving/utils/identify.mjs';

/**
Expand Down Expand Up @@ -240,7 +239,7 @@ export default (behavior) => {
return this.links.base?.href;
}
notify.error('No createApi');
throw ouch(401, 'No createApi');
throw createError({ statusCode: 401, message: 'No createApi' });
},

/**
Expand All @@ -258,7 +257,7 @@ export default (behavior) => {
return this.links.self?.href;
}
notify.error('No fetchApi');
throw ouch(401, 'No fetchApi');
throw createError({ statusCode: 401, message: 'No fetchApi' });
},

/**
Expand All @@ -273,7 +272,7 @@ export default (behavior) => {
return this.links.self?.href;
}
notify.error('No links.self');
throw ouch(400, 'No links.self');
throw createError({ statusCode: 400, message: 'No links.self' });
},

/**
Expand Down
3 changes: 1 addition & 2 deletions app/utils/ving/dateTime.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { format, parseISO, parseJSON, parse, getUnixTime } from 'date-fns';
import { ouch } from '#ving/utils/ouch.mjs';
import { isArray, isString, isUndefined } from '#ving/utils/identify.mjs';


Expand Down Expand Up @@ -29,7 +28,7 @@ export const determineDate = (input) => {
return parseJSON(input);
}
console.error('Have no idea what type this date is: ', input);
throw ouch(400, 'bad date object', input);
throw createError({ statusCode: 400, message: 'Have no idea what type this date is: ' + input });
}

/**
Expand Down

0 comments on commit c366b51

Please sign in to comment.