Skip to content

Commit

Permalink
fix: error msg for invalid puter-ocr urls
Browse files Browse the repository at this point in the history
  • Loading branch information
KernelDeimos committed Jan 10, 2025
1 parent 14cc8f7 commit 6a6bfa0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
18 changes: 15 additions & 3 deletions src/backend/src/services/drivers/CoercionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const APIError = require("../../api/APIError");
const BaseService = require("../BaseService");
const { TypeSpec } = require("./meta/Construct");
const { TypedValue } = require("./meta/Runtime");
Expand Down Expand Up @@ -67,9 +68,20 @@ class CoercionService extends BaseService {
},
coerce: async typed_value => {
this.log.noticeme('coercion is running!');
const response = await CoercionService.MODULES.axios.get(typed_value.value, {
responseType: 'stream',
});

const response = await(async () => {
try {
return await CoercionService.MODULES.axios.get(typed_value.value, {
responseType: 'stream',
});
} catch (e) {
APIError.create('field_invalid', null, {
key: 'url',
expected: 'web URL',
got: 'error during request: ' + e.message,
});
}
})();


return new TypedValue({
Expand Down
17 changes: 14 additions & 3 deletions src/backend/src/services/drivers/FileFacade.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const { MultiValue } = require("../../util/multivalue");
const { stream_to_buffer } = require("../../util/streamutil");
const { PassThrough } = require("stream");
const { LLRead } = require("../../filesystem/ll_operations/ll_read");
const APIError = require("../../api/APIError");

/**
* @class FileFacade
Expand Down Expand Up @@ -89,9 +90,19 @@ class FileFacade extends AdvancedBase {
});

this.values.add_factory('stream', 'web_url', async web_url => {
const response = await FileFacade.MODULES.axios.get(web_url, {
responseType: 'stream',
});
const response = await(async () => {
try {
return await FileFacade.MODULES.axios.get(web_url, {
responseType: 'stream',
});
} catch (e) {
throw APIError.create('field_invalid', null, {
key: 'url',
expected: 'web URL',
got: 'error during request: ' + e.message,
});
}
})();

return response.data;
});
Expand Down

0 comments on commit 6a6bfa0

Please sign in to comment.