After request schema

This is the function schema which defines all the middleware to be run after calling the sdk.request method. This will be the schema which will be used to inject middleware into your code.

The after request middleware takes in 3 arguments:

  • Response: The response you receive from the request
  • sdk
  • bundle
after.jsindex.js
Copy
Copied
const stringify = (response, sdk, bundle) => {
    if (response.status === 200 || response.status === 201) {
        return response.text();
    } else {
        throw new Error("Internal server errror: check with system admin");
    }

    return response;
};

module.exports = {
    afters: [stringify]
};
Copy
Copied
const after = require("./src/after");

module.exports = {
    afterResponse: [...after.afters],
};

In the above example we can see that on the app schema, afterResponse property is an array of functions which includes a function that converts the response into text if status code is 200 or 201 and throws error if the status code is anything else.

Please note that afterResponse method is called after each sdk.request method is called.

We'd love to hear from you!
Rate this content:
Still have a question?
 
Ask the community.