Add messages to all api calls

This commit is contained in:
Ean Milligan (Bastion) 2022-06-22 01:57:38 -04:00
parent cc45794497
commit dba1976a8e
11 changed files with 22 additions and 18 deletions

View File

@ -205,7 +205,7 @@ const start = async (): Promise<void> => {
requestEvent.respondWith(stdResp.TooManyRequests('Slow down, servers are expensive and this bot is free to use.')); requestEvent.respondWith(stdResp.TooManyRequests('Slow down, servers are expensive and this bot is free to use.'));
} else { } else {
// Alert API user that they shouldn't be doing this // Alert API user that they shouldn't be doing this
requestEvent.respondWith(stdResp.Forbidden('')); requestEvent.respondWith(stdResp.Forbidden('Why are you here?'));
} }
} }
})(); })();

View File

@ -76,10 +76,10 @@ export const apiKeyDelete = async (requestEvent: Deno.RequestEvent, query: Map<s
} }
} else { } else {
// Alert API user that they shouldn't be doing this // Alert API user that they shouldn't be doing this
requestEvent.respondWith(stdResp.Forbidden('')); requestEvent.respondWith(stdResp.Forbidden('You can only delete your own key.'));
} }
} else { } else {
// Alert API user that they messed up // Alert API user that they messed up
requestEvent.respondWith(stdResp.BadRequest('')); requestEvent.respondWith(stdResp.BadRequest(stdResp.Strings.missingParams));
} }
}; };

View File

@ -30,10 +30,10 @@ export const apiChannel = async (requestEvent: Deno.RequestEvent, query: Map<str
} }
} else { } else {
// Alert API user that they shouldn't be doing this // Alert API user that they shouldn't be doing this
requestEvent.respondWith(stdResp.Forbidden('')); requestEvent.respondWith(stdResp.Forbidden('You can only view your own channels.'));
} }
} else { } else {
// Alert API user that they messed up // Alert API user that they messed up
requestEvent.respondWith(stdResp.BadRequest('')); requestEvent.respondWith(stdResp.BadRequest(stdResp.Strings.missingParams));
} }
}; };

View File

@ -44,11 +44,11 @@ export const apiKey = async (requestEvent: Deno.RequestEvent, query: Map<string,
return; return;
} else { } else {
// Send basic OK to indicate key has been sent // Send basic OK to indicate key has been sent
requestEvent.respondWith(stdResp.OK('')); requestEvent.respondWith(stdResp.OK('Email Sent.'));
return; return;
} }
} else { } else {
// Alert API user that they messed up // Alert API user that they messed up
requestEvent.respondWith(stdResp.BadRequest('')); requestEvent.respondWith(stdResp.BadRequest(stdResp.Strings.missingParams));
} }
}; };

View File

@ -35,10 +35,10 @@ export const apiKeyAdmin = async (requestEvent: Deno.RequestEvent, query: Map<st
} }
} else { } else {
// Only allow the db admin to use this API // Only allow the db admin to use this API
requestEvent.respondWith(stdResp.Forbidden('')); requestEvent.respondWith(stdResp.Forbidden(stdResp.Strings.restricted));
} }
} else { } else {
// Alert API user that they messed up // Alert API user that they messed up
requestEvent.respondWith(stdResp.BadRequest('')); requestEvent.respondWith(stdResp.BadRequest(stdResp.Strings.missingParams));
} }
}; };

View File

@ -119,6 +119,6 @@ export const apiRoll = async (requestEvent: Deno.RequestEvent, query: Map<string
} }
} else { } else {
// Alert API user that they shouldn't be doing this // Alert API user that they shouldn't be doing this
requestEvent.respondWith(stdResp.BadRequest('')); requestEvent.respondWith(stdResp.BadRequest(stdResp.Strings.missingParams));
} }
}; };

View File

@ -29,10 +29,10 @@ export const apiChannelAdd = async (requestEvent: Deno.RequestEvent, query: Map<
} }
} else { } else {
// Alert API user that they shouldn't be doing this // Alert API user that they shouldn't be doing this
requestEvent.respondWith(stdResp.Forbidden('')); requestEvent.respondWith(stdResp.Forbidden('You can only add channels to your key.'));
} }
} else { } else {
// Alert API user that they messed up // Alert API user that they messed up
requestEvent.respondWith(stdResp.BadRequest('')); requestEvent.respondWith(stdResp.BadRequest(stdResp.Strings.missingParams));
} }
}; };

View File

@ -36,10 +36,10 @@ export const apiChannelManageActive = async (requestEvent: Deno.RequestEvent, qu
} }
} else { } else {
// Alert API user that they shouldn't be doing this // Alert API user that they shouldn't be doing this
requestEvent.respondWith(stdResp.Forbidden('')); requestEvent.respondWith(stdResp.Forbidden('You can only manage your own channels.'));
} }
} else { } else {
// Alert API user that they messed up // Alert API user that they messed up
requestEvent.respondWith(stdResp.BadRequest('')); requestEvent.respondWith(stdResp.BadRequest(stdResp.Strings.missingParams));
} }
}; };

View File

@ -40,10 +40,10 @@ export const apiChannelManageBan = async (requestEvent: Deno.RequestEvent, query
} }
} else { } else {
// Alert API user that they shouldn't be doing this // Alert API user that they shouldn't be doing this
requestEvent.respondWith(stdResp.Forbidden('')); requestEvent.respondWith(stdResp.Forbidden(stdResp.Strings.restricted));
} }
} else { } else {
// Alert API user that they messed up // Alert API user that they messed up
requestEvent.respondWith(stdResp.BadRequest('')); requestEvent.respondWith(stdResp.BadRequest(stdResp.Strings.missingParams));
} }
}; };

View File

@ -46,10 +46,10 @@ export const apiKeyManage = async (requestEvent: Deno.RequestEvent, query: Map<s
} }
} else { } else {
// Alert API user that they shouldn't be doing this // Alert API user that they shouldn't be doing this
requestEvent.respondWith(stdResp.Forbidden('')); requestEvent.respondWith(stdResp.Forbidden('You can only manage your own key.'));
} }
} else { } else {
// Alert API user that they messed up // Alert API user that they messed up
requestEvent.respondWith(stdResp.BadRequest('')); requestEvent.respondWith(stdResp.BadRequest(stdResp.Strings.missingParams));
} }
}; };

View File

@ -16,4 +16,8 @@ export default {
OK: (customText: string) => genericResponse(customText, Status.OK), OK: (customText: string) => genericResponse(customText, Status.OK),
RequestTimeout: (customText: string) => genericResponse(customText, Status.RequestTimeout), RequestTimeout: (customText: string) => genericResponse(customText, Status.RequestTimeout),
TooManyRequests: (customText: string) => genericResponse(customText, Status.TooManyRequests), TooManyRequests: (customText: string) => genericResponse(customText, Status.TooManyRequests),
Strings: {
missingParams: 'Missing Parameters.',
restricted: 'This API is restricted.',
},
}; };