mirror of
https://github.com/HeyPuter/puter.git
synced 2025-02-02 23:28:39 +08:00
fix: error msg for invalid puter-ocr urls
This commit is contained in:
parent
14cc8f7bc0
commit
6a6bfa034f
@ -17,6 +17,7 @@
|
|||||||
* You should have received a copy of the GNU Affero General Public License
|
* 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/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
const APIError = require("../../api/APIError");
|
||||||
const BaseService = require("../BaseService");
|
const BaseService = require("../BaseService");
|
||||||
const { TypeSpec } = require("./meta/Construct");
|
const { TypeSpec } = require("./meta/Construct");
|
||||||
const { TypedValue } = require("./meta/Runtime");
|
const { TypedValue } = require("./meta/Runtime");
|
||||||
@ -67,9 +68,20 @@ class CoercionService extends BaseService {
|
|||||||
},
|
},
|
||||||
coerce: async typed_value => {
|
coerce: async typed_value => {
|
||||||
this.log.noticeme('coercion is running!');
|
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({
|
return new TypedValue({
|
||||||
|
@ -23,6 +23,7 @@ const { MultiValue } = require("../../util/multivalue");
|
|||||||
const { stream_to_buffer } = require("../../util/streamutil");
|
const { stream_to_buffer } = require("../../util/streamutil");
|
||||||
const { PassThrough } = require("stream");
|
const { PassThrough } = require("stream");
|
||||||
const { LLRead } = require("../../filesystem/ll_operations/ll_read");
|
const { LLRead } = require("../../filesystem/ll_operations/ll_read");
|
||||||
|
const APIError = require("../../api/APIError");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class FileFacade
|
* @class FileFacade
|
||||||
@ -89,9 +90,19 @@ class FileFacade extends AdvancedBase {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.values.add_factory('stream', 'web_url', async web_url => {
|
this.values.add_factory('stream', 'web_url', async web_url => {
|
||||||
const response = await FileFacade.MODULES.axios.get(web_url, {
|
const response = await(async () => {
|
||||||
responseType: 'stream',
|
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;
|
return response.data;
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user