Alankazam
08/15/2022, 7:03 PMrp_st
08/16/2022, 4:41 AMAlankazam
08/16/2022, 5:32 AMrp_st
08/16/2022, 5:37 AMts
import { Error as STError } from "supertokens-node"
let err: any;
if (STError.isErrorFromSuperTokens(err)) {
let {fromRecipe, message, payload, type} = err;
}
Alankazam
08/16/2022, 5:58 AMAlankazam
08/16/2022, 4:59 PMAlankazam
08/16/2022, 5:02 PMrp_st
08/16/2022, 5:05 PMAlankazam
08/16/2022, 5:08 PMAlankazam
08/16/2022, 5:09 PMrp_st
08/16/2022, 5:36 PMrp_st
08/16/2022, 5:36 PMAlankazam
08/16/2022, 6:48 PM.after((request) => {
const response = request.response as APIGatewayProxyResult;
const body = JSON.parse(response.body);
if (body.status !== 'OK') {
throw new SuperTokensError(body);
}
})
.onError((request) => {
log('ERROR:: authentication::', request.error);
const handledError = handleError(request.error);
request.response = errorResponse(handledError.statusCode, handledError);
});
Basically I'm converting the non ok response from Supertokens to a custom error class.
So I can add new fields in the response and change the status codeAlankazam
08/16/2022, 6:48 PMrp_st
08/16/2022, 6:49 PMrp_st
08/16/2022, 6:49 PMrp_st
08/16/2022, 6:49 PMrp_st
08/16/2022, 6:50 PMAlankazam
08/16/2022, 6:51 PM