mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 15:48:11 -05:00
Server now logs the messages of its bad responses instead of just sending them to the client. Added a script that migrated bad ObjectIds in purchased items.
This commit is contained in:
parent
25f157f201
commit
b33fee406b
2 changed files with 32 additions and 0 deletions
|
@ -0,0 +1,21 @@
|
|||
var usersWithPurchases = db.users.find({"purchased.items": {$exists: true}}).toArray();
|
||||
var itemsConverted = 0;
|
||||
var usersConverted = 0;
|
||||
for (var i = 0; i < usersWithPurchases.length; ++i) {
|
||||
var user = usersWithPurchases[i];
|
||||
var items = user.purchased.items;
|
||||
var convertThisUser = false;
|
||||
for (var j = 0; j < items.length; ++j) {
|
||||
var item = items[j];
|
||||
if (typeof item != 'string') {
|
||||
items[j] = '' + item;
|
||||
++itemsConverted;
|
||||
convertThisUser = true;
|
||||
}
|
||||
}
|
||||
if (convertThisUser) {
|
||||
db.users.save(user);
|
||||
++usersConverted;
|
||||
}
|
||||
}
|
||||
print("Had to convert", itemsConverted, "items and", usersConverted, "users");
|
|
@ -1,13 +1,18 @@
|
|||
log = require 'winston'
|
||||
|
||||
module.exports.custom = (res, code=500, message='Internal Server Error') ->
|
||||
log.debug "#{code}: #{message}"
|
||||
res.send code, message
|
||||
res.end()
|
||||
|
||||
module.exports.unauthorized = (res, message='Unauthorized') ->
|
||||
# TODO: The response MUST include a WWW-Authenticate header field
|
||||
log.debug "401: #{message}"
|
||||
res.send 401, message
|
||||
res.end()
|
||||
|
||||
module.exports.forbidden = (res, message='Forbidden') ->
|
||||
log.debug "403: #{message}"
|
||||
res.send 403, message
|
||||
res.end()
|
||||
|
||||
|
@ -16,27 +21,33 @@ module.exports.notFound = (res, message='Not found.') ->
|
|||
res.end()
|
||||
|
||||
module.exports.badMethod = (res, allowed=['GET', 'POST', 'PUT', 'PATCH'], message='Method Not Allowed') ->
|
||||
log.debug "405: #{message}"
|
||||
allowHeader = _.reduce allowed, ((str, current) -> str += ', ' + current)
|
||||
res.set 'Allow', allowHeader # TODO not sure if these are always the case
|
||||
res.send 405, message
|
||||
res.end()
|
||||
|
||||
module.exports.conflict = (res, message='Conflict. File exists') ->
|
||||
log.debug "409: #{message}"
|
||||
res.send 409, message
|
||||
res.end()
|
||||
|
||||
module.exports.badInput = (res, message='Unprocessable Entity. Bad Input.') ->
|
||||
log.debug "422: #{message}"
|
||||
res.send 422, message
|
||||
res.end()
|
||||
|
||||
module.exports.serverError = (res, message='Internal Server Error') ->
|
||||
log.debug "500: #{message}"
|
||||
res.send 500, message
|
||||
res.end()
|
||||
|
||||
module.exports.gatewayTimeoutError = (res, message='Gateway timeout') ->
|
||||
log.debug "504: #{message}"
|
||||
res.send 504, message
|
||||
res.end()
|
||||
|
||||
module.exports.clientTimeout = (res, message='The server did not receive the client response in a timely manner') ->
|
||||
log.debug "408: #{message}"
|
||||
res.send 408, message
|
||||
res.end()
|
||||
|
|
Loading…
Reference in a new issue