Skip to content

invoking a function that returns a 500 error throws instead of returning the error object #14

@netanelgilad

Description

@netanelgilad

@claude I have this example code usage:

try {
            const { data, error: functionError } = await base44.functions.invoke('testApiKey');
            console.log(functionError);
            
            if (functionError || (data && data.error)) {
                throw new Error(functionError?.message || data.error);
            }

            setApiKeyStatus(data);
        } catch (err) {
            console.log('this was an error', err);
            setError(err.message);
        } finally {

and a backend function:

Deno.serve(async (req) => {
    try {
        throw new Error('my life');
    } catch (error) {
        return new Response(JSON.stringify({ error: error.message }), {
            status: 500,
            headers: { "Content-Type": "application/json" },
        });
    }
});

and instead of returning the error in functionError, it's going to the catch clause.
and this is what is printed

[pages/HelloWorld.js] this was an error 
AxiosError {message: 'Request failed with status code 500', name: 'AxiosError', code: 'ERR_BAD_RESPONSE', config: {…}, request: XMLHttpRequest, …}
code
: 
"ERR_BAD_RESPONSE"
config
: 
{transitional: {…}, adapter: Array(3), transformRequest: Array(1), transformResponse: Array(1), timeout: 0, …}
message
: 
"Request failed with status code 500"
name
: 
"AxiosError"

let's fix this so that it returns the error as part of the function invokation result, and add a test to verify it

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions