code update recorded at: 04/04/25 07:42:28
This commit is contained in:
commit
198a8bb64a
|
|
@ -0,0 +1,70 @@
|
||||||
|
// BOILER_CODE_START
|
||||||
|
|
||||||
|
import crypto from 'crypto'
|
||||||
|
|
||||||
|
class EventNotSupportedException extends Error {
|
||||||
|
constructor(message) {
|
||||||
|
super(message);
|
||||||
|
this.name = 'EventNotSupportedException';
|
||||||
|
this.statusCode = 451;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class InvalidEventPayloadException extends Error {
|
||||||
|
constructor(message) {
|
||||||
|
super(message);
|
||||||
|
this.statusCode = 452;
|
||||||
|
this.name = 'InvalidEventPayloadException';
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RetryErrorException extends Error {
|
||||||
|
constructor(message) {
|
||||||
|
super(message);
|
||||||
|
this.statusCode = 453;
|
||||||
|
this.name = 'RetryErrorException';
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateSha256Hash(input) {
|
||||||
|
return crypto.createHash('sha256').update(input).digest('hex');
|
||||||
|
}
|
||||||
|
|
||||||
|
export const handler = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const obj = req.body;
|
||||||
|
modifyObj(obj);
|
||||||
|
res.setHeader('Content-Type', 'application/json');
|
||||||
|
res.send(JSON.stringify(obj));
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
const statusCode = error.statusCode || 500;
|
||||||
|
res.statusCode = statusCode;
|
||||||
|
res.setHeader('Content-Type', 'application/json');
|
||||||
|
res.send(JSON.stringify(statusCode === 500
|
||||||
|
? { message: error.message }
|
||||||
|
: { name: error.name, message: error.message, statusCode }));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// BOILER_CODE_END
|
||||||
|
|
||||||
|
function modifyObj(obj) {
|
||||||
|
// Enter your code here
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Exceptions available:
|
||||||
|
throw new EventNotSupportedException('your message here');
|
||||||
|
throw new InvalidEventPayloadException('your message here');
|
||||||
|
throw new RetryErrorException('your message here');
|
||||||
|
|
||||||
|
Method for generating 256 hash code for a String:
|
||||||
|
let hashOfAString = generateSha256Hash(input);
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user