"""Standard header-based error responses.""" from owsresponse import response from owsrequest.constants import errors def create_error_missing_account_headers(): """Generate error for when both headers are required but missing. e.g. required: [Grass-Account-Type, Grass-Account-Id] get( '/route', headers={} """ return response.create_error_response( code=errors.ERROR_CODE_MISSING_GRASS_HEADERS, message=errors.ERROR_MESSAGE_MISSING_GRASS_HEADERS) def create_error_incomplete_account_headers(): """Generate error for when one header is missing. e.g. required: [Grass-Account-Type, Grass-Account-Id, Orchard-User-Id] get( '/route', headers={ 'Grass-Account-Type': 'vendor', 'Orchard-User-Id': 'alw:16888'} """ return response.create_error_response( code=errors.ERROR_CODE_INCOMPLETE_GRASS_HEADERS, message=errors.ERROR_MESSAGE_INCOMPLETE_GRASS_HEADERS) def create_error_unexpected_grass_headers(): """Generate error for unexpected account headers.""" return response.create_error_response( code=errors.ERROR_CODE_UNEXPECTED_GRASS_HEADERS, message=errors.ERROR_MESSAGE_UNEXPECTED_GRASS_HEADERS) def create_error_account_without_user(): """Generate error for account without user in the header. e.g. required: [Grass-Account-Type, Grass-Account-Id, Orchard-User-Id] get( '/route', headers={ 'Grass-Account-Type': 'vendor', 'Grass-Account-Id': 7123} """ return response.create_error_response( code=errors.ERROR_CODE_ACCOUNT_WITHOUT_USER, message=errors.ERROR_MESSAGE_ACCOUNT_WITHOUT_USER) def create_error_forbidden_user(): """Generate error for forbidden user.""" return response.create_error_response( code=errors.ERROR_CODE_FORBIDDEN_USER, message=errors.ERROR_MESSAGE_FORBIDDEN_USER, status=403) def create_error_forbidden(): """Generate access denied error.""" return response.create_error_response( code=errors.ERROR_CODE_FORBIDDEN, message=errors.ERROR_MESSAGE_FORBIDDEN, status=403) def create_error_user_does_not_exist(): """Generate error for user does not exist.""" return response.create_error_response( code=errors.ERROR_CODE_USER_DOES_NOT_EXIST, message=errors.ERROR_MESSAGE_USER_DOES_NOT_EXIST, status=404) def create_error_user_mismatch(): """Generate error when parameter user does not match header user. e.g. get('/route/alw:16888', headers={'Orchard-User-Id': 'alw:555'} """ return response.create_error_response( code=errors.ERROR_CODE_INCOMPLETE_PROFILE_HEADERS, message=errors.ERROR_MESSAGE_INCOMPLETE_PROFILE_HEADERS) def create_error_subaccount_does_not_exist(): """Generate error for subaccount does not exist.""" return response.create_error_response( code=errors.ERROR_CODE_SUBACCOUNT_DOES_NOT_EXIST, message=errors.ERROR_MESSAGE_SUBACCOUNT_DOES_NOT_EXIST, status=404) def create_error_authorization_header_not_found(): """Generate error for authorization header not found.""" return response.create_error_response( code=errors.UNAUTHORIZED_CODE, message=errors.UNAUTHORIZED_MESSAGE[errors.AUTH_NOT_FOUND], status=403) def create_error_vendor_mismatch(): """Generate error for vendor mismatch. e.g. get( '/route/vendor/7123', headers={ 'Grass-Account-Type': 'vendor', 'Grass-Account-Id': 999, 'Orchard-User-Id': 'alw:16888'} """ return response.create_error_response( code=errors.ERROR_CODE_VENDOR_MISMATCH, message=errors.ERROR_MESSAGE_VENDOR_MISMATCH) def create_error_subaccount_mismatch(): """Generate error for subaccount mismatch. e.g. get( '/route/subaccount/333', headers={ 'Grass-Account-Type': 'subaccount', 'Grass-Account-Id': 444, 'Orchard-User-Id': 'alw:5656'} """ return response.create_error_response( code=errors.ERROR_CODE_SUBACCOUNT_MISMATCH, message=errors.ERROR_MESSAGE_SUBACCOUNT_MISMATCH) def create_error_incomplete_profile_headers(): """Generate error for incomplete profile headers. e.g. required: [Orchard-Profile-Type, Orchard-Profile-Id] get( '/route', headers={ 'Orchard-Profile-Type': 'ArtistProfile'} """ return response.create_error_response( code=errors.ERROR_CODE_INCOMPLETE_PROFILE_HEADERS, message=errors.ERROR_MESSAGE_INCOMPLETE_PROFILE_HEADERS) def create_error_profile_type_mismatch(): """Generate error: route param profile_type does not match header. e.g. get( '/route/profile_type/ArtistProfile/profile_id/555', headers={ 'Orchard-Profile-Type': 'LabelManagerProfile', 'Orchard-Profile-Id': 555} """ return response.create_error_response( code=errors.ERROR_CODE_PROFILE_TYPE_MISMATCH, message=errors.ERROR_MESSAGE_PROFILE_TYPE_MISMATCH) def create_error_profile_id_mismatch(): """Generate error: route param profile_id does not match header. e.g. get( '/route/profile_type/ArtistProfile/profile_id/555', headers={ 'Orchard-Profile-Type': 'ArtistProfile', 'Orchard-Profile-Id': 888} """ return response.create_error_response( code=errors.ERROR_CODE_PROFILE_ID_MISMATCH, message=errors.ERROR_MESSAGE_PROFILE_ID_MISMATCH) def create_error_identity_id_mismatch(): """Generate error: route param identity_id does not match header. e.g. get( '/route/identity_id/5bfd388b43c05c4f27222cdd', headers={ 'Orchard-Identity-Id': 5cd2dd3390c6cb0f6927b8c8} """ return response.create_error_response( code=errors.ERROR_CODE_IDENTITY_ID_MISMATCH, message=errors.ERROR_MESSAGE_IDENTITY_ID_MISMATCH)