Skip to content

[FEATURE] Return error message sent from backend instead of standard message in ResponseError #821

Open
@raghibomar786

Description

Describe the feature

In case of error, it is important to know the reason of failure. In our use case, we need to display the reason for failure to the user. The backend sends the reason for failure in the error message, but pdk internally returns standard static message : "Response returned an error code". Is there a way to get the actual error message that the backend returns? If not, we should update this to pass back the actual error message sent by the backend.

Code:

protected async request(context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction): Promise<Response> {
        const { url, init } = await this.createFetchParams(context, initOverrides);
        const response = await this.fetchApi(url, init);
        if (response && (response.status >= 200 && response.status < 300)) {
            return response;
        }
        throw new ResponseError(response, 'Response returned an error code');
    }
export class ResponseError extends Error {
    override name: "ResponseError" = "ResponseError";
    constructor(public response: Response, msg?: string) {
        super(msg);
    }
}

Use Case

There's a UI screen that can fail for multiple reason. We need to tell the user the exact reason for the failure. We send the exact reason from backend but there's no way to get it in frontend with the current code.

Proposed Solution

response is already present in the code, just need to propagate the message in the final function.

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

PDK version used

0.23.38

What languages will this feature affect?

Typescript, Java

Environment details (OS name and version, etc.)

Linux

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions