Cleanup app error codes
1. The error classes (like AppsError) now take a 3rd argument details. We can attach anything in this 3rd argument and this gets sent in the REST response as well. 2. The HttpError class is now HttpError(statusCode, errorOrMessage). If it's an error object, it will take the message and other things which were attached above from it and send them across. Previously, we used to mark this case an internal error all the time. 3. AppsError only has generic codes now. The UI code then simply checks for additional information that we attached to show errors. For example, BAD_FIELD will have a field: 'xx' indicating which field is at fault. ALREADY_EXISTS has information on which domain or port caused a problem. The advantage here is we can drop all these error codes that are specific to each model code. 4. Maybe some day, we can remove all these error classes and have only one generic class. AppsError right now is pretty generic already. We can use that error code everywhere... No need to translate errors also everywhere. 5. Finally, in the router code, I have this function toHttpError (in apps.js) which is also so much cleaner than what we have now. We keep writing the same stuff over and over.
This commit is contained in:
@@ -41,12 +41,9 @@ function toHttpError(appError) {
|
||||
case AppsError.NOT_FOUND:
|
||||
return new HttpError(404, appError);
|
||||
case AppsError.ALREADY_EXISTS:
|
||||
case AppsError.PORT_CONFLICT:
|
||||
case AppsError.LOCATION_CONFLICT:
|
||||
case AppsError.BAD_STATE:
|
||||
return new HttpError(409, appError);
|
||||
case AppsError.BAD_FIELD:
|
||||
case AppsError.BAD_CERTIFICATE:
|
||||
return new HttpError(400, appError);
|
||||
case AppsError.PLAN_LIMIT:
|
||||
return new HttpError(402, appError);
|
||||
|
||||
Reference in New Issue
Block a user